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

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

[nongnu] elpa/evil-nerd-commenter f3d4f7ef29 070/235: better integration


From: ELPA Syncer
Subject: [nongnu] elpa/evil-nerd-commenter f3d4f7ef29 070/235: better integration with org-mode v1.3.0
Date: Thu, 6 Jan 2022 02:59:36 -0500 (EST)

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

    better integration with org-mode v1.3.0
---
 README.org                 |  9 +++++---
 evil-nerd-commenter-pkg.el |  2 +-
 evil-nerd-commenter.el     | 52 +++++++++++++++++++++++++++++++++++-----------
 pkg.sh                     |  2 +-
 4 files changed, 48 insertions(+), 17 deletions(-)

diff --git a/README.org b/README.org
index f555a5378a..32fe058eb3 100644
--- a/README.org
+++ b/README.org
@@ -1,4 +1,4 @@
-* evil-nerd-commenter (version 1.2.9)
+* evil-nerd-commenter (version 1.3.0)
 
 *Please note this program could be used independently without evil-mode!*
 
@@ -26,6 +26,9 @@ Here is the live demo:
 I'll provide long-term support for this plugin for *ANY language* in the 
future. Here is a example how I work around 
[[https://github.com/redguardtoo/evil-nerd-commenter/issues/3][a bug in 
autoconf.el]].
 * Install
 evil-nerd-commenter is already uploaded to [[http://marmalade-repo.org/]]. So 
the best way to install it is using Emacs' package manager.
+
+** Perfect integration with org-mode
+The programming language embedded in org file will automatically be detected 
and *correct* comment syntax will be used!
 * Set up
 ** The easy way (RECOMMENDED)
 Nothing to set up if install it in the way as I suggested.
@@ -124,9 +127,9 @@ For example:
 #+END_SRC
 
 *** evilnc-toggle-invert-comment-line-by-line
-Toggle flag evilnc-invert-comment-line-by-line. When this flag is true, the 
command "evilnc-comment-or-uncomment-lines", 
"evilnc-comment-or-uncomment-to-the-line", and 
"evilnc-comment-or-uncomment-paragraphs" will be influenced.
+Toggle flag evilnc-invert-comment-line-by-line.
 
-These commands will *invert* each line's comment status instead comment the 
whole thing.
+When the flag is true, the command "evilnc-comment-or-uncomment-lines", 
"evilnc-comment-or-uncomment-to-the-line", and 
"evilnc-comment-or-uncomment-paragraphs" will be influenced. They will *invert* 
each line's comment status instead comment the whole thing.
 
 *** evilnc-kill-to-line
 Kill from the current line to the user-specified line.
diff --git a/evil-nerd-commenter-pkg.el b/evil-nerd-commenter-pkg.el
index f136b37bd6..822813fe14 100644
--- a/evil-nerd-commenter-pkg.el
+++ b/evil-nerd-commenter-pkg.el
@@ -1,2 +1,2 @@
-(define-package "evil-nerd-commenter" "1.2.9"
+(define-package "evil-nerd-commenter" "1.3.0"
                 "Comment/uncomment lines efficiently. Like Nerd Commenter in 
Vim")
diff --git a/evil-nerd-commenter.el b/evil-nerd-commenter.el
index 213a31ed4c..49d39e0097 100644
--- a/evil-nerd-commenter.el
+++ b/evil-nerd-commenter.el
@@ -4,7 +4,7 @@
 
 ;; Author: Chen Bin <chenbin.sh@gmail.com>
 ;; URL: http://github.com/redguardtoo/evil-nerd-commenter
-;; Version: 1.2.9
+;; Version: 1.3.0
 ;; Keywords: commenter vim line evil
 ;;
 ;; This file is not part of GNU Emacs.
@@ -194,7 +194,7 @@
       ;; comment (line-beginning-position line-end-position)
       ;; (setq old-b (line-beginning-position)
       ;; (forward-line -1)
-      ;; (if (= old-b (line-beginning-position)) we did't move, out of loop
+      ;; (if (= old-b (line-beginning-position)) we did not move, out of loop
       ;; (if (<= (line-end-position) beg)), out of region, out of loop
       (while (not done)
         (setq b (line-beginning-position))
@@ -202,16 +202,43 @@
         (funcall (if (comment-only-p b e)
                      'uncomment-region 'comment-region)
                  b e)
+
         (forward-line -1)
         (when (or (= (line-beginning-position) b) (< (line-end-position) beg))
           (setq done t))
         ))))
 
+(defun evilnc--working-on-region (beg end fn)
+  (let ((info (org-edit-src-find-region-and-lang))
+        lang
+        lang-f
+        old-flag)
+
+    (when info
+      (setq lang (or (cdr (assoc (nth 2 info) org-src-lang-modes))
+                     (nth 2 info)))
+      (setq lang (if (symbolp lang) (symbol-name lang) lang))
+      (setq lang-f (intern (concat lang "-mode")))
+      )
+
+    ;; turn on 3rd party language's major-mode temporarily
+    (if lang-f (funcall lang-f))
+
+    (if evilnc-invert-comment-line-by-line
+        (evilnc--invert-comment beg end)
+      (funcall fn beg end))
+
+    ;; turn off  3rd party language's major-mode temporarily and clean the shit
+    (when lang-f
+      (setq old-flag org-inhibit-startup-visibility-stuff)
+      ;; avoid org file automatically collapsed
+      (setq org-inhibit-startup-visibility-stuff t)
+      (org-mode)
+      (setq org-inhibit-startup-visibility-stuff old-flag))
+    ))
+
 (defun evilnc--comment-or-uncomment-region (beg end)
-  (if evilnc-invert-comment-line-by-line
-      (evilnc--invert-comment beg end)
-    (comment-or-uncomment-region beg end)
-      ))
+  (evilnc--working-on-region beg end 'comment-or-uncomment-region))
 
 ;; ==== below this line are public commands
 ;;;###autoload
@@ -244,14 +271,15 @@ Paragraphs are separated by empty lines."
               (re-search-forward "^[ \t]*[^ \t]" nil t)
 
               (if (<= (line-beginning-position) e)
-                    (throw 'break i)))
-            (throw 'break i))
+                  (throw 'break i)))
+          (throw 'break i))
         ))
     (when (<= b e)
       (save-excursion
         (evilnc--fix-buggy-major-modes)
         (evilnc--comment-or-uncomment-region b e)
-        ))))
+        ))
+    ))
 
 ;;;###autoload
 (defun evilnc-comment-or-uncomment-to-the-line (&optional LINENUM)
@@ -415,12 +443,12 @@ Save in REGISTER or in the kill-ring with YANK-HANDLER."
                   (/= (char-before end) ?\n))
               (/= beg (point-min))
               (=  (char-before beg) ?\n))
-         (comment-or-uncomment-region (1- beg) end))
+         (evilnc--comment-or-uncomment-region (1- beg) end))
         ((eq type 'line)
-           (comment-or-uncomment-region beg end))
+           (evilnc--comment-or-uncomment-region beg end))
         (t
          (let ((newpos (evilnc--extend-to-whole-comment beg end) ))
-           (comment-or-uncomment-region (nth 0 newpos) (nth 1 newpos))
+           (evilnc--comment-or-uncomment-region (nth 0 newpos) (nth 1 newpos))
            )
          ))
        ;; place cursor on beginning of line
diff --git a/pkg.sh b/pkg.sh
index 09b373ab33..d59bc8165d 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,5 +1,5 @@
 #!/bin/bash
-pkg=evil-nerd-commenter-1.2.9
+pkg=evil-nerd-commenter-1.3.0
 mkdir $pkg
 cp README.org $pkg
 cp *.el $pkg



reply via email to

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