[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
- [nongnu] elpa/evil-nerd-commenter 60b8862864 210/235: clean code, (continued)
- [nongnu] elpa/evil-nerd-commenter 60b8862864 210/235: clean code, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter b7fc023492 220/235: fixed: `add-to-list’ can’t use lexical var `cands’, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter b8ac35fe01 225/235: add evilnc-yank-and-comment-operator, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter b8a2601117 006/235: some tip, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter ef643d604d 007/235: updated README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter d3581dcf64 014/235: workaround autoconf.el comment bug, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 72965eab13 019/235: remove warning when installing package, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter a074fed790 033/235: Added check for evil-define-operator, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 71995b8ac3 034/235: Updated readme, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 0e24866151 048/235: updated README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter f3d4f7ef29 070/235: better integration with org-mode v1.3.0,
ELPA Syncer <=
- [nongnu] elpa/evil-nerd-commenter 1edf652fc6 086/235: explain how NOT to use comma as leader key, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter befd4da216 117/235: Comment operator should not be filling registers and kill-ring, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 9220e93853 128/235: Merge pull request #56 from syohex/correct-package-headers, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 7a441580ae 141/235: Save position in org-mode src blocks., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 80f503be1e 161/235: typo in doc, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 16dcffac65 163/235: Fix doc-string typo and length, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 4dca3cc33d 012/235: Merge pull request #4 from darth10/patch-1, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter b4b18c8190 017/235: you can copy and comment lines in one command, upgraded to version 0.0.6, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 01556c89ba 021/235: add live demo, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 2b68b829fe 023/235: fixed regression since 0.0.6: cannot comment region, ELPA Syncer, 2022/01/06