branch: elpa/evil-nerd-commenter
commit 8f6fafcce901a7a588f946b26d2e21c65e36e843
Author: Chen Bin <[email protected]>
Commit: Chen Bin <[email protected]>
better algorithm to extract comments in imenu
---
README.org | 6 ++++--
evil-nerd-commenter.el | 41 +++++++++++++++++++++++++++++++++++++----
pkg.sh | 2 +-
3 files changed, 42 insertions(+), 7 deletions(-)
diff --git a/README.org b/README.org
index 5050b348ab..e1d865fec4 100644
--- a/README.org
+++ b/README.org
@@ -1,4 +1,4 @@
-* evil-nerd-commenter (v3.2.1)
+* evil-nerd-commenter (v3.2.2)
[[http://melpa.org/#/evil-nerd-commenter][file:http://melpa.org/packages/evil-nerd-commenter-badge.svg]]
[[http://stable.melpa.org/#/evil-nerd-commenter][file:http://stable.melpa.org/packages/evil-nerd-commenter-badge.svg]]
@@ -8,7 +8,7 @@ A [[http://www.vim.org/scripts/script.php?script_id=1218][Nerd
Commenter]] emula
I recommend using it with Evil though Evil is optional.
-Tested on Emacs 23.4, 24.3, 24.4, 24.5
+Tested on Emacs 24.4, 24.5, 25.3
* Why?
** A simple use case on the efficiency
@@ -30,6 +30,8 @@ The code snippet embedded in org file will automatically be
detected and *correc
evil-nerd-commenter is already uploaded to [[http://melpa.org]]. The best way
to install is Emacs package manager.
* Setup
Please note NO key bindings are setup automatically. You need use following
ways to setup key bindings.
+
+Please note since v3.2.2, Emacs v24.4+ is required.
** Use recommended key bindings
Insert =(evilnc-default-hotkeys)= into =~/.emacs= to use key bindings preset
for both evil and non-evil mode. This is recommended way.
diff --git a/evil-nerd-commenter.el b/evil-nerd-commenter.el
index 6f047a326e..1217633d6b 100644
--- a/evil-nerd-commenter.el
+++ b/evil-nerd-commenter.el
@@ -5,6 +5,7 @@
;; Author: Chen Bin <[email protected]>
;; URL: http://github.com/redguardtoo/evil-nerd-commenter
;; Version: 3.2.1
+;; Package-Requires: ((emacs "24.4"))
;; Keywords: commenter vim line evil
;;
;; This file is not part of GNU Emacs.
@@ -709,6 +710,19 @@ If NO-EVIL-KEYBINDINGS is t, we don't define keybindings
in EVIL."
(define-key evil-inner-text-objects-map evilnc-comment-text-object
'evilnc-inner-comment)
(define-key evil-outer-text-objects-map evilnc-comment-text-object
'evilnc-outer-commenter)))))
+
+(defun evilnc-frame-wide-string (s)
+ "Build summary from S."
+ (let* ((w (frame-width))
+ ;; display kill ring item in one line
+ (key (replace-regexp-in-string "[ \t]*[\n\r]+[ \t]*" "\\\\n" s)))
+ ;; strip the whitespace
+ (setq key (replace-regexp-in-string "^[ \t]+" "" key))
+ ;; fit to the minibuffer width
+ (if (> (length key) w)
+ (setq key (concat (substring key 0 (- w 4)) "...")))
+ key))
+
;;;###autoload
(defun evilnc-imenu-create-index-function ()
"Imenu function find comments."
@@ -724,7 +738,8 @@ If NO-EVIL-KEYBINDINGS is t, we don't define keybindings in
EVIL."
;; learn this skill from etags-select
;; use simple string search to speed up searching
(while searching
- (setq beg (search-forward comment-start (point-max) t))
+ ;; C/C++ might use "/* " as comment-start
+ (setq beg (search-forward (string-trim comment-start) (point-max) t))
;; OK, it's comment
(cond
((not beg)
@@ -741,13 +756,31 @@ If NO-EVIL-KEYBINDINGS is t, we don't define keybindings
in EVIL."
(setq end (search-forward comment-end (point-max) t))))
(cond
((and end (> end beg))
- (setq str (buffer-substring-no-properties beg end))
- (when (and (not (string-match-p "^[ \t]*$" str))
+ (setq str (string-trim (buffer-substring-no-properties beg end)))
+ ;; no empty line
+ (setq str (replace-regexp-in-string "[\r\n]+" "\n" str))
+ ;; could be multi-lines comment
+ (let* ((a (split-string str "[\r\n]+"))
+ (pre-p (concat "^[ \t]*["
+ (string-trim comment-start)
+ "][ \t]*"))
+ (post-p (concat "[ \t]*["
+ (string-trim comment-end)
+ "][ \t]*$")))
+ ;; remove empty lines
+ (setq a (delq nil (mapcar (lambda (s)
+ (setq s (replace-regexp-in-string
pre-p "" s))
+ (setq s (replace-regexp-in-string
post-p "" s))
+ (setq s (string-trim s))
+ (unless (string-match-p "^[ \t]*$"
s) s))
+ a)))
+ (setq str (mapconcat 'identity a "\n" )))
+ (when (and (not (string-match-p "^[ \t\n\r]*$" str))
(> (length str) evilnc-min-comment-length-for-imenu))
(setq m (make-marker))
(set-marker m beg)
(add-to-list 'cands
- (cons (format "%d:%s" linenum str) m)
+ (cons (evilnc-frame-wide-string (format "%d:%s"
linenum str)) m)
t))
(goto-char (min (1+ end) (point-max))))
(t
diff --git a/pkg.sh b/pkg.sh
index 555b4a925d..e723e5adda 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,6 +1,6 @@
#!/bin/bash
name=evil-nerd-commenter
-version=3.2.1
+version=3.2.2
pkg=$name-$version
mkdir $pkg
cp *.el $pkg