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

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

[nongnu] elpa/evil-nerd-commenter d3581dcf64 014/235: workaround autocon


From: ELPA Syncer
Subject: [nongnu] elpa/evil-nerd-commenter d3581dcf64 014/235: workaround autoconf.el comment bug
Date: Thu, 6 Jan 2022 02:59:31 -0500 (EST)

branch: elpa/evil-nerd-commenter
commit d3581dcf64faf2182d12ca85abe9519e88c511ab
Author: chen bin <chenbin.sh@gmail.com>
Commit: chen bin <chenbin.sh@gmail.com>

    workaround autoconf.el comment bug
---
 README.org                 |  9 ++++++---
 evil-nerd-commenter-pkg.el |  2 +-
 evil-nerd-commenter.el     | 30 ++++++++++++++++++++++++++----
 pkg.sh                     |  2 +-
 4 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/README.org b/README.org
index f8beccc135..99b2a8f0f5 100644
--- a/README.org
+++ b/README.org
@@ -1,15 +1,18 @@
-* evil-nerd-commenter (current version 0.0.3)
+* evil-nerd-commenter (current version 0.0.4)
 As a developer, I often need comment/uncomment lines for debugging or adding 
some short comment in the code block.
 
 As I know, the [[http://www.vim.org/scripts/script.php?script_id=1218][Nerd 
Commenter]] for Vim is the most efficient way to doing this thing. 
Unfortunately, there is no similar plugin in Emacs.
 
 That's why I develop this Nerd Commenter simulator for Emacs people.
-* Why evil-nerd-commenter is better? Show me a simple use case!
+* Why evil-nerd-commenter is better? 
+** A simple use case on the efficiency
 Say you want to comment out nine lines. Instead pressing "C-space M-9 C-n 
M-;", now you can press "M-9 M-;" or ",9ci".
 
 The key point is you need NOT mark any text to comment line(s)!
 
-So you strike less keys to comment code than the origial "M-x comment-dwim".
+So you strike less keys to comment code than the original "M-x comment-dwim".
+** The commenter will ALWAYS work even the official Emacs has some bug
+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.
 * Set up
diff --git a/evil-nerd-commenter-pkg.el b/evil-nerd-commenter-pkg.el
index 6ca316b37a..774e64af0e 100644
--- a/evil-nerd-commenter-pkg.el
+++ b/evil-nerd-commenter-pkg.el
@@ -1,2 +1,2 @@
-(define-package "evil-nerd-commenter" "0.0.3"
+(define-package "evil-nerd-commenter" "0.0.4"
                 "Comment/uncomment lines efficiently. Like Nerd Commenter in 
Vim")
diff --git a/evil-nerd-commenter.el b/evil-nerd-commenter.el
index 82e79ad413..93ee158a3f 100644
--- a/evil-nerd-commenter.el
+++ b/evil-nerd-commenter.el
@@ -4,7 +4,7 @@
 ;; Author: Chen Bin <chenbin DOT sh AT gmail>
 ;; URL: http://github.com/redguardtoo/evil-nerd-commenter
 ;; Keywords: commenter vim line evil
-;; Version: 0.0.3
+;; Version: 0.0.4
 
 ;; This file is not part of GNU Emacs.
 
@@ -21,7 +21,7 @@
 ;;; Code:
 
 ;; shamelessly copied from goto-line
-(defun evilnc-goto-line (line)
+(defun evilnc--goto-line (line)
   (save-restriction
     (widen)
     (goto-char (point-min))
@@ -30,6 +30,25 @@
       (forward-line (1- line))))
   )
 
+(defun evilnc--fix-buggy-major-modes ()
+  "fix major modes whose comment regex is buggy.
+@see http://lists.gnu.org/archive/html/bug-gnu-emacs/2013-03/msg00891.html";
+  (when (string= major-mode "autoconf-mode")
+    ;; since comment-use-syntax is nil in autoconf.el, the comment-start-skip 
need
+    ;; make sure the its first parenthesized expression match the string 
exactly before
+    ;; the "dnl", check the comment-start-skip in lisp-mode may give you some 
hint.
+    ;; See code in (defun comment-search-forward) from emacs 24.2.1:
+    ;; (if (not comment-use-syntax)
+    ;;     (if (re-search-forward comment-start-skip limit noerror)
+    ;;     (or (match-end 1) (match-beginning 0))
+    ;; My regex make sure (match-end 1) return the position of comment starter
+    (when (and (boundp 'comment-use-syntax) (not comment-use-syntax))
+        ;; Maybe autoconf.el will (setq comment-use-syntax t) in the future?
+        (setq comment-start-skip "^\\(\\s*\\)\\(dnl\\|#\\) +")
+      )
+    )
+  )
+
 ;;;###autoload
 (defun evilnc-comment-or-uncomment-to-the-line (&optional LINENUM)
   "Comment or uncomment from the current line to the LINENUM line"
@@ -38,15 +57,16 @@
       (let ((b (line-beginning-position))
             (e (line-end-position)))
         (save-excursion
-          (evilnc-goto-line LINENUM)
+          (evilnc--goto-line LINENUM)
           (if (< (line-beginning-position) b)
               (setq b (line-beginning-position)))
           (if (> (line-end-position) e)
               (setq e (line-end-position)))
+          (evilnc--fix-buggy-major-modes)
           (comment-or-uncomment-region b e)
           )
         )
-  ))
+    ))
 
 ;;;###autoload
 (defun evilnc-toggle-comment-empty-lines ()
@@ -74,6 +94,7 @@
         (save-excursion
           (forward-line (- NUM 1))
           (setq e (line-end-position))
+          (evilnc--fix-buggy-major-modes)
           (comment-or-uncomment-region b e)
           )
         )
@@ -86,6 +107,7 @@
         (setq b (line-beginning-position))
         (goto-char e)
         (setq e (line-end-position))
+        (evilnc--fix-buggy-major-modes)
         (comment-or-uncomment-region b e)))
     ))
 
diff --git a/pkg.sh b/pkg.sh
index 6e9d0020e7..0deb2a7a5a 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,5 +1,5 @@
 #!/bin/bash
-pkg=evil-nerd-commenter-0.0.3
+pkg=evil-nerd-commenter-0.0.4
 mkdir $pkg
 cp README.org $pkg
 cp *.el $pkg



reply via email to

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