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

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

[nongnu] elpa/treesit-fold 07fe2d17f4 249/417: feature: Add minor-mode f


From: ELPA Syncer
Subject: [nongnu] elpa/treesit-fold 07fe2d17f4 249/417: feature: Add minor-mode for line comment (#45)
Date: Mon, 1 Jul 2024 10:02:31 -0400 (EDT)

branch: elpa/treesit-fold
commit 07fe2d17f442325025c8f9efdb1aca8a7d49ff56
Author: Jen-Chieh Shen <jcs090218@gmail.com>
Commit: GitHub <noreply@github.com>

    feature: Add minor-mode for line comment (#45)
    
    * feature: Add minor-mode for line comment
    
    * Update doc
    
    * update emoji
    
    * Fix checkdoc
---
 README.md            |  27 ++++++++++++++++++++++-----
 etc/line-comment.gif | Bin 0 -> 498924 bytes
 ts-fold.el           |  18 ++++++++++++++----
 3 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/README.md b/README.md
index dd96dfae29..334642bfc5 100644
--- a/README.md
+++ b/README.md
@@ -40,6 +40,8 @@ to provide code folding based on the tree-sitter syntax tree.
     - [📝 Summary](#-summary)
       - [🖥 Usage](#-usage-2)
       - [📝 Customization](#-customization-1)
+    - [🌫️ Line-Comment folding](#-line-comment-folding)
+      - [🖥 Usage](#-usage-3)
   - [🔰 Contribute](#-contribute)
     - [❓ How to add a folding parser?](#-how-to-add-a-folding-parser)
     - [🔍 Where can I look for tree-sitter 
node?](#-where-can-i-look-for-tree-sitter-node)
@@ -85,11 +87,12 @@ The following are the functions provided by `ts-fold-mode`
 Commands for enabling `ts-fold`:
 
 | Commands                         | Description                               
                                                          |
-| -------------------------------- | 
---------------------------------------------------------------------------------------------------
 |
+|----------------------------------|-----------------------------------------------------------------------------------------------------|
 | `ts-fold-mode`                   | enable `ts-fold-mode` in the current 
buffer.                                                        |
 | `global-ts-fold-mode`            | enable `ts-fold-mode` whenever 
tree-sitter is turned on and the major mode is supported by ts-fold. |
 | `ts-fold-indicators-mode`        | enable ts-fold with indicators in the 
current buffer. See [plugins section](#-indicators-mode).     |
 | `global-ts-fold-indicators-mode` | enable ts-fold with indicators globally. 
See [plugins section](#-indicators-mode).                  |
+| `ts-fold-line-comment-mode`      | enable line comment folding.              
                                                          |
 
 Commands for using `ts-fold`.
 
@@ -147,15 +150,15 @@ mode and the value being another alist of fold 
definitions.
 
 ```elisp
 ;; Example of ts-fold-range-alist's structure
-'((c-mode . c-folding-definitions) ;; <language>-folding-definitions is 
structured as shown below
-  (css-mode . css-folding-definitions)
-  (go-mode . go-folding-definitions)
+'((c-mode     . c-folding-definitions) ;; <language>-folding-definitions is 
structured as shown below
+  (css-mode   . css-folding-definitions)
+  (go-mode    . go-folding-definitions)
   (scala-mode . scala-folding-definitions)
   ...)
 
 ;; Examle of a folding definition alist
 (setq css-folding-definitions
-    (block . ts-fold-range-seq)
+    (block   . ts-fold-range-seq)
     (comment . ts-fold-range-c-like-comment))
 ```
 
@@ -496,6 +499,20 @@ As can be seen `ts-fold-summary--generic` is a very 
helpful function since it
 removes the provided delimiter and returns the first line. often this will be
 enough.
 
+### 🌫️ Line-Comment folding
+
+<p align="center">
+<img src="./etc/line-comment.gif" width="80%" height="80%"/>
+</p>
+
+This plugin makes line comment into foldable range.
+
+#### 🖥 Usage
+
+  ```
+  M-x ts-fold-line-comment-mode
+  ```
+
 ## 🔰 Contribute
 
 [![PRs 
Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com)
diff --git a/etc/line-comment.gif b/etc/line-comment.gif
new file mode 100644
index 0000000000..02c509a7e4
Binary files /dev/null and b/etc/line-comment.gif differ
diff --git a/ts-fold.el b/ts-fold.el
index 2995f1f2ed..ad11fd9623 100644
--- a/ts-fold.el
+++ b/ts-fold.el
@@ -124,6 +124,8 @@ the fold in a cons cell.  See `ts-fold-range-python' for an 
example."
 ;; (@* "Externals" )
 ;;
 
+(defvar ts-fold-indicators-mode)
+
 (declare-function ts-fold-indicators-refresh "ts-fold-indicators.el")
 
 ;;
@@ -153,8 +155,8 @@ the fold in a cons cell.  See `ts-fold-range-python' for an 
example."
     (ts-fold-open-all)))
 
 (defun ts-fold--tree-sitter-trigger ()
-  "Turn `ts-fold-mode' on and off alongside `tree-sitter-mode'
-when in a mode ts-fold can act on."
+  "Turn `ts-fold-mode' on and off alongside `tree-sitter-mode' when in a mode
+ts-fold can act on."
   (if (and tree-sitter-mode (ts-fold-usable-mode-p))
       (ts-fold-mode 1)
     (ts-fold-mode -1)))
@@ -169,7 +171,7 @@ when in a mode ts-fold can act on."
 
 ;;;###autoload
 (define-minor-mode global-ts-fold-mode
-  "Use `ts-fold-mode' wherever possible"
+  "Use `ts-fold-mode' wherever possible."
   :group 'ts-fold
   :init-value nil
   :lighter nil
@@ -188,6 +190,13 @@ when in a mode ts-fold can act on."
   (let ((mode (or mode major-mode)))
     (alist-get mode ts-fold-range-alist)))
 
+;;;###autoload
+(define-minor-mode ts-fold-line-comment-mode
+  "Enable line comment folding."
+  :group 'ts-fold
+  :init-value nil
+  (when ts-fold-indicators-mode (ts-fold-indicators-refresh)))
+
 ;;
 ;; (@* "Core" )
 ;;
@@ -399,7 +408,8 @@ For arguments NODE and OFFSET, see function 
`ts-fold-range-seq' for
 more information.
 
 Argument PREFIX is the comment prefix in string."
-  (when-let* ((first-node (ts-fold--continuous-node-prefix node prefix nil))
+  (when-let* ((ts-fold-line-comment-mode)  ; XXX: Check enabled!?
+              (first-node (ts-fold--continuous-node-prefix node prefix nil))
               (last-node (ts-fold--continuous-node-prefix node prefix t))
               (prefix-len (length prefix))
               (beg (+ (tsc-node-start-position first-node) prefix-len))



reply via email to

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