Skip to content

Commit 9a04a89

Browse files
committed
Add support.
1 parent efe82e1 commit 9a04a89

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

docstr.el

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@
7474
:type 'string
7575
:group 'docstr)
7676

77-
(defcustom docstr-desc-param "Param desc here.."
77+
(defcustom docstr-desc-param "Param description here.."
7878
"Description for parameter document string."
7979
:type 'string
8080
:group 'docstr)
8181

82-
(defcustom docstr-desc-return "Returns desc here.."
82+
(defcustom docstr-desc-return "Returns description here.."
8383
"Description for return document string."
8484
:type 'string
8585
:group 'docstr)
@@ -140,19 +140,21 @@ variable. Argument DESC is the description of VAR."
140140

141141
(defun docstr--enable ()
142142
"Enable `docstr' in current buffer."
143-
(advice-add (key-binding (kbd "RET")) :after #'docstr--trigger-return)
144-
(cl-case major-mode
145-
(csharp-mode (advice-add (key-binding (kbd "/")) :after #'docstr--trigger-csharp))
146-
(lua-mode (advice-add (key-binding (kbd "-")) :after #'docstr--trigger-lua))
147-
(python-mode (advice-add (key-binding (kbd "\"")) :after #'docstr--trigger-python))))
143+
(when (docstr-supports-p)
144+
(advice-add (key-binding (kbd "RET")) :after #'docstr--trigger-return)
145+
(cl-case major-mode
146+
(csharp-mode (advice-add (key-binding (kbd "/")) :after #'docstr--trigger-csharp))
147+
(lua-mode (advice-add (key-binding (kbd "-")) :after #'docstr--trigger-lua))
148+
(python-mode (advice-add (key-binding (kbd "\"")) :after #'docstr--trigger-python)))))
148149

149150
(defun docstr--disable ()
150151
"Disable `docstr' in current buffer."
151-
(advice-remove (key-binding (kbd "RET")) #'docstr--trigger-return)
152-
(cl-case major-mode
153-
(csharp-mode (advice-remove (key-binding (kbd "/")) #'docstr--trigger-csharp))
154-
(lua-mode (advice-remove (key-binding (kbd "-")) #'docstr--trigger-lua))
155-
(python-mode (advice-remove (key-binding (kbd "\"")) #'docstr--trigger-python))))
152+
(when (docstr-supports-p)
153+
(advice-remove (key-binding (kbd "RET")) #'docstr--trigger-return)
154+
(cl-case major-mode
155+
(csharp-mode (advice-remove (key-binding (kbd "/")) #'docstr--trigger-csharp))
156+
(lua-mode (advice-remove (key-binding (kbd "-")) #'docstr--trigger-lua))
157+
(python-mode (advice-remove (key-binding (kbd "\"")) #'docstr--trigger-python)))))
156158

157159
;;;###autoload
158160
(define-minor-mode docstr-mode
@@ -165,10 +167,14 @@ variable. Argument DESC is the description of VAR."
165167
;; (@* "Core" )
166168
;;
167169

170+
(defun docstr-supports-p ()
171+
"Return non-nil if current `major-mode' supports by `docstr'."
172+
(memq major-mode (docstr-major-modes)))
173+
168174
(defun docstr-major-modes ()
169175
"List of `major-mode' that supports document string."
170176
(let (lst)
171-
(dolist (m docstr-writers-alist) (push (car m) docstr-writers-alist))
177+
(dolist (m docstr-writers-alist) (push (car m) lst))
172178
(reverse lst)))
173179

174180
(defun docstr-get-writer ()

0 commit comments

Comments
 (0)