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

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

[nongnu] elpa/jade-mode d8324d4820 078/128: Improve comment line/region


From: ELPA Syncer
Subject: [nongnu] elpa/jade-mode d8324d4820 078/128: Improve comment line/region function
Date: Sat, 29 Jan 2022 08:24:48 -0500 (EST)

branch: elpa/jade-mode
commit d8324d482052a31a356f9d092ff0324871edc025
Author: Travis Jefferson <tjefferson@signpost.com>
Commit: Travis Jefferson <tjefferson@signpost.com>

    Improve comment line/region function
    
        - change default comment token to -//
        - higlight -// blocks in comment face
        - improve comment line/region functionality
---
 example.jade |  2 ++
 jade-mode.el | 40 ++++++++++++++++++++++++++++++----------
 2 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/example.jade b/example.jade
index ba438263e6..8554312eee 100644
--- a/example.jade
+++ b/example.jade
@@ -1,5 +1,6 @@
 !!!
 html(lang="en")
+  -// consult http://jade-lang.com for a full language reference
   head
     title My page
   body.bp
@@ -11,6 +12,7 @@ html(lang="en")
           li
       #content
         // here is a real comment
+        -// here is another real comment, this is probably a better default
         a(href = 'http://www.google.com') http://www.google.com
         - if (youAreUsingJade)
           p You are amazing
diff --git a/jade-mode.el b/jade-mode.el
index d1ab4ea46d..828fd9ece1 100644
--- a/jade-mode.el
+++ b/jade-mode.el
@@ -21,16 +21,36 @@
   "Returns t when line contains only whitespace chars, nil otherwise."
   (string-match-p "^\\s-*$" (jade-line-as-string)))
 
-;; command to comment/uncomment text
 (defun jade-comment-dwim (arg)
-  "Comment or uncomment current line or region in a smart way.
-For detail, see `comment-dwim'."
+  "Comment or uncomment current line or region in a smart way."
   (interactive "*P")
   (require 'newcomment)
-  (let (
-        (comment-start "//") (comment-end "")
-        )
-    (comment-dwim arg)))
+  (let ((start (if (region-active-p)
+
+                   ;; when region is active, use beginning of line at
+                   ;; beginning of region (this way we don't start
+                   ;; commenting in the middle of a line)
+                   (progn
+                     (save-excursion
+                       (goto-char (region-beginning))
+                       (point-at-bol)))
+
+                 ;; without a region, just use beginning of current line
+                 (point-at-bol)))
+
+        ;; same logic applies for end of line/region
+        (end (if (region-active-p)
+                 (progn
+                   (save-excursion
+                     (goto-char (region-end))
+                     (point-at-eol)))
+               (point-at-eol))))
+
+    ;; once we pick good values for start/end of region, simply use
+    ;; `comment-or-uncomment-region' from `newcomment' lib, and skip
+    ;; to next line for convenience
+    (comment-or-uncomment-region start end)
+    (forward-line)))
 
 (defconst jade-keywords
   (eval-when-compile
@@ -64,7 +84,7 @@ For detail, see `comment-dwim'."
     (,"\\(?:^[ {2,}]*\\(?:[a-z0-9_:\\-]*\\)\\)?\\(#[A-Za-z0-9\-\_]*[^ ]\\)" 1 
font-lock-variable-name-face) ;; id
     (,"\\(?:^[ {2,}]*\\(?:[a-z0-9_:\\-]*\\)\\)?\\(\\.[A-Za-z0-9\-\_]*\\)" 1 
font-lock-type-face) ;; class name
     (,"^[ {2,}]*[a-z0-9_:\\-]*" 0 font-lock-function-name-face) ;; tag name
-    (,"^\\s-*\\(//.*\\)" 1 font-lock-comment-face t) ;; jade block comments
+    (,"^\\s-*\\(-?//.*\\)" 1 font-lock-comment-face t) ;; jade block comments
 
     ;; remove highlighting from lines opening with a pipe `|'
     ;; e.g. | keywords like for should not be highlighted here
@@ -233,8 +253,8 @@ Follows indentation behavior of `indent-rigidly'."
   (setq major-mode 'jade-mode)
 
   ;; comment syntax
-  (set (make-local-variable 'comment-start) "// ")
-  (set (make-local-variable 'comment-start-skip) "//\\s-*")
+  (set (make-local-variable 'comment-start) "-// ")
+  (set (make-local-variable 'comment-start-skip) "-//\\s-*")
 
   (setq-default jade-tab-width 2)
   (setq-local indent-line-function 'jade-indent-line)



reply via email to

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