emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/evil-nerd-commenter 8809dccfdb 223/235: user can customize


From: ELPA Syncer
Subject: [nongnu] elpa/evil-nerd-commenter 8809dccfdb 223/235: user can customize comment style
Date: Thu, 6 Jan 2022 02:59:50 -0500 (EST)

branch: elpa/evil-nerd-commenter
commit 8809dccfdbd7eb4cb34fa42794a80de5469e11d6
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>

    user can customize comment style
---
 README.org                      | 14 ++++++++++++++
 evil-nerd-commenter-operator.el |  8 ++++----
 evil-nerd-commenter.el          | 35 +++++++++++++++++++++++++++++------
 pkg.sh                          |  2 +-
 4 files changed, 48 insertions(+), 11 deletions(-)

diff --git a/README.org b/README.org
index 55f166b2d4..da9b7d50b7 100644
--- a/README.org
+++ b/README.org
@@ -282,6 +282,20 @@ Most popular programming languages are supported.
 You can set up =evilnc-original-above-comment-when-copy-and-comment= to decide 
which style to use when =evilnc-copy-and-comment-lines= or 
=evilnc-copy-and-comment-operator=,
 - Place the commented out text above original text
 - Or place the original text above commented out text
+** Customize comment style
+Most commands call =evilnc-comment-or-uncomment-region-function=.
+
+You can modify this variable to customize the comment style.
+
+#+begin_src elisp
+(with-eval-after-load 'evil-nerd-commenter
+  (defun my-comment-or-uncomment-region (beg end)
+    (let* ((comment-start "aaa")
+           (comment-end "bbb"))
+      (evilnc-comment-or-uncomment-region-internal beg end)))
+  (setq evilnc-comment-or-uncomment-region-function
+        'my-comment-or-uncomment-region))
+#+end_src
 * Credits
 - [[https://github.com/lalopmak][Lally Oppenheimer (AKA lalopmak)]] added the 
support for text-object in Evil
 - [[https://github.com/ryuslash][Tom Willemse (AKA ryuslash)]] provided the 
fix to make Emacs 24.4 work
diff --git a/evil-nerd-commenter-operator.el b/evil-nerd-commenter-operator.el
index df5a0a71a4..65820bb3a2 100644
--- a/evil-nerd-commenter-operator.el
+++ b/evil-nerd-commenter-operator.el
@@ -145,7 +145,7 @@ Or expand the region to contain whole lines if it's not 
comment and certain cond
   (cond
    ((eq type 'block)
     (let* ((newpos (evilnc-expand-to-whole-comment-or-line beg end) ))
-      (evil-apply-on-block #'evilnc--comment-or-uncomment-region
+      (evil-apply-on-block #'evilnc-comment-or-uncomment-region
                            (car newpos)
                            (cdr newpos)
                            nil)))
@@ -156,11 +156,11 @@ Or expand the region to contain whole lines if it's not 
comment and certain cond
              (/= (char-before end) ?\n))
          (/= beg (point-min))
          (=  (char-before beg) ?\n))
-    (evilnc--comment-or-uncomment-region (1- beg) end))
+    (evilnc-comment-or-uncomment-region (1- beg) end))
 
    ((eq type 'line)
     ;; comment whole line, for now
-    (evilnc--comment-or-uncomment-region beg
+    (evilnc-comment-or-uncomment-region beg
                                          (save-excursion
                                            (goto-char (1- end))
                                            (line-end-position))))
@@ -168,7 +168,7 @@ Or expand the region to contain whole lines if it's not 
comment and certain cond
    (t
     (when (and beg end)
       (let* ((newpos (evilnc-expand-to-whole-comment-or-line beg end)))
-        (evilnc--comment-or-uncomment-region (car newpos) (cdr newpos))))))
+        (evilnc-comment-or-uncomment-region (car newpos) (cdr newpos))))))
 
   ;; place cursor on beginning of line
   (if (and (called-interactively-p 'any) (eq type 'line))
diff --git a/evil-nerd-commenter.el b/evil-nerd-commenter.el
index d3e19fad32..ac487410a6 100644
--- a/evil-nerd-commenter.el
+++ b/evil-nerd-commenter.el
@@ -3,7 +3,7 @@
 ;; Author: Chen Bin <chenbin DOT sh AT gmail.com>
 
 ;; URL: http://github.com/redguardtoo/evil-nerd-commenter
-;; Version: 3.5.1
+;; Version: 3.5.2
 ;; Package-Requires: ((emacs "24.4"))
 ;; Keywords: convenience evil
 ;;
@@ -111,6 +111,19 @@
 ;;   (local-set-key (kbd "M-;") 'evilnc-comment-or-uncomment-lines))
 ;; (add-hook 'matlab-mode-hook 'matlab-mode-hook-config)
 ;;
+;; Most commands call `evilnc-comment-or-uncomment-region-function'.
+;; You can modify this variable to customize the comment style,
+;;
+;;   (with-eval-after-load 'evil-nerd-commenter
+;;     (defun my-comment-or-uncomment-region (beg end)
+;;       (let* ((comment-start "aaa")
+;;              (comment-end "bbb"))
+;;         (evilnc-comment-or-uncomment-region-internal beg end)))
+;;     (setq evilnc-comment-or-uncomment-region-function
+;;           'my-comment-or-uncomment-region))
+;;
+;; See "Options Controlling Comments" in Emacs manual for comment options.
+;;
 ;; See https://github.com/redguardtoo/evil-nerd-commenter for detail.
 ;;
 ;;; Code:
@@ -130,6 +143,10 @@
   "If t then invert region comment status line by line.
 Please note it has NOT effect on evil text object!")
 
+(defvar evilnc-comment-or-uncomment-region-function
+  'evilnc-comment-or-uncomment-region-internal
+  "Comment or uncomment region.")
+
 (defvar evilnc-cpp-like-comment-syntax-modes
   '(java-mode
     javascript-mode
@@ -464,7 +481,8 @@ Code snippets embedded in Org-mode is identified and right 
`major-mode' is used.
       (goto-char end)
       (web-mode-comment-or-uncomment))))
 
-(defun evilnc--comment-or-uncomment-region (beg end)
+;;;###autoload
+(defun evilnc-comment-or-uncomment-region-internal (beg end)
   "Comment or uncomment region from BEG to END."
   (cond
    ((eq major-mode 'web-mode)
@@ -476,6 +494,11 @@ Code snippets embedded in Org-mode is identified and right 
`major-mode' is used.
    (t
     (evilnc--working-on-region beg end 'comment-or-uncomment-region))))
 
+;;;###autoload
+(defun evilnc-comment-or-uncomment-region (beg end)
+  "Comment or uncomment region from BEG to END."
+  (funcall evilnc-comment-or-uncomment-region-function beg end))
+
 (defun evilnc--current-line-num ()
   "Get current line number."
   (save-restriction
@@ -551,7 +574,7 @@ Paragraphs are separated by empty lines."
   (evilnc-do-paragraphs
    (lambda (b e)
      (evilnc--fix-buggy-major-modes)
-     (evilnc--comment-or-uncomment-region b e))
+     (evilnc-comment-or-uncomment-region b e))
    num))
 
 ;;;###autoload
@@ -568,7 +591,7 @@ Paragraphs are separated by empty lines."
           (if (> (line-end-position) e)
               (setq e (line-end-position)))
           (evilnc--fix-buggy-major-modes)
-          (evilnc--comment-or-uncomment-region b e)))))
+          (evilnc-comment-or-uncomment-region b e)))))
 
 ;;;###autoload
 (defun evilnc-quick-comment-or-uncomment-to-the-line (&optional last-digits)
@@ -632,7 +655,7 @@ CORRECT comment syntax will be used for 
C++/Java/Javascript."
           (setq num (- 0 num)))
         (evilnc--operation-on-lines-or-region '(lambda (b e)
                                                  
(evilnc--fix-buggy-major-modes)
-                                                 
(evilnc--comment-or-uncomment-region b e))
+                                                 
(evilnc-comment-or-uncomment-region b e))
                                               num))
       (goto-char orig-pos)))))
 
@@ -737,7 +760,7 @@ Then we operate the expanded region.  NUM is ignored."
 (defun evilnc-version ()
   "The version number."
   (interactive)
-  (message "3.5.1"))
+  (message "3.5.2"))
 
 (defvar evil-normal-state-map)
 (defvar evil-visual-state-map)
diff --git a/pkg.sh b/pkg.sh
index 028799e1b2..6950ef636a 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 name=evil-nerd-commenter
-version=3.5.1
+version=3.5.2
 pkg=$name-$version
 mkdir $pkg
 cp *.el $pkg



reply via email to

[Prev in Thread] Current Thread [Next in Thread]