forked from redguardtoo/evil-nerd-commenter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevil-nerd-commenter-operator.el
72 lines (60 loc) · 2.22 KB
/
evil-nerd-commenter-operator.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
;;; evil-nerd-commenter-operator.el --- Provides an evil operator for evil-nerd-commenter
;; Copyright (C) 2013-2015, Chen Bin
;; Author: Chen Bin <[email protected]>
;; URL: http://github.com/redguardtoo/evil-nerd-commenter
;; Version: 2.3
;; Keywords: commenter vim line evil
;;
;; This file is not part of GNU Emacs.
;;; License:
;; This file is part of evil-nerd-commenter
;;
;; evil-nerd-commenter is free software: you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as published
;; by the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; evil-nerd-commenter is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Provides an operator for evil-mode.
;;; Code:
(require 'evil nil 'noerror)
(evil-define-operator evilnc-comment-operator (beg end type)
"Comments text from BEG to END with TYPE."
(interactive "<R>")
(cond
((eq type 'block)
(let ((newpos (evilnc--extend-to-whole-comment beg end) ))
(evil-apply-on-block #'evilnc--comment-or-uncomment-region (nth 0 newpos) (nth 1 newpos) nil)
)
)
((and (eq type 'line)
(= end (point-max))
(or (= beg end)
(/= (char-before end) ?\n))
(/= beg (point-min))
(= (char-before beg) ?\n))
(evilnc--comment-or-uncomment-region (1- beg) end))
((eq type 'line)
(evilnc--comment-or-uncomment-region beg (1- end)))
(t
(let ((newpos (evilnc--extend-to-whole-comment beg end) ))
(evilnc--comment-or-uncomment-region (nth 0 newpos) (nth 1 newpos))
)
))
;; place cursor on beginning of line
(when (and (evil-called-interactively-p)
(eq type 'line))
(evil-first-non-blank)))
(provide 'evil-nerd-commenter-operator)
;;; evil-nerd-commenter-operator.el ends here
;; Local Variables:
;; byte-compile-warnings: (not free-vars unresolved)
;; End: