[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/treesit-fold c0e9bb7f3e 344/417: fix: Improve Julia rules
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/treesit-fold c0e9bb7f3e 344/417: fix: Improve Julia rules |
Date: |
Mon, 1 Jul 2024 10:03:02 -0400 (EDT) |
branch: elpa/treesit-fold
commit c0e9bb7f3e76dab45a890cea756fb913076564cf
Author: JenChieh <jcs090218@gmail.com>
Commit: Jen-Chieh Shen <jcs090218@gmail.com>
fix: Improve Julia rules
---
ts-fold-parsers.el | 23 ++++++++++++++---------
ts-fold-summary.el | 4 ++--
ts-fold-util.el | 6 ++----
ts-fold.el | 45 +++++++++++++++++++++++++++++++++++++++------
4 files changed, 57 insertions(+), 21 deletions(-)
diff --git a/ts-fold-parsers.el b/ts-fold-parsers.el
index 87a57459f9..3705e3db03 100644
--- a/ts-fold-parsers.el
+++ b/ts-fold-parsers.el
@@ -55,7 +55,9 @@
(declare-function ts-fold-range-fish-case "ts-fold.el")
(declare-function ts-fold-range-haskell-function "ts-fold.el")
(declare-function ts-fold-range-html "ts-fold.el")
-(declare-function ts-fold-range-julia "ts-fold.el")
+(declare-function ts-fold-range-julia-function "ts-fold.el")
+(declare-function ts-fold-range-julia-if "ts-fold.el")
+(declare-function ts-fold-range-julia-let "ts-fold.el")
(declare-function ts-fold-range-kotlin-when "ts-fold.el")
(declare-function ts-fold-range-lisp-function "ts-fold.el")
(declare-function ts-fold-range-llvm-label "ts-fold.el")
@@ -320,16 +322,19 @@
"Rule set for Julia."
'((block_comment . (ts-fold-range-seq 1 -1))
(for_statement . (ts-fold-range-seq 2 -2))
- (function_definition . ts-fold-range-julia)
- (if_statement . (ts-fold-range-seq 1 -2))
- (let_statement . (ts-fold-range-seq 2 -2))
- (macro_definition . ts-fold-range-julia)
- (module_definition . ts-fold-range-julia)
- (quote_statement . ts-fold-range-julia)
- (struct_definition . ts-fold-range-julia)
+ (function_definition . ts-fold-range-julia-function)
+ (if_statement . ts-fold-range-julia-if)
+ (let_statement . ts-fold-range-julia-let)
+ (macro_definition . ts-fold-range-julia-function)
+ (module_definition . ts-fold-range-julia-function)
+ (quote_statement . ts-fold-range-julia-function)
+ (struct_definition . ts-fold-range-julia-function)
(triple_string . (ts-fold-range-seq 2 -2))
(try_statement . (ts-fold-range-seq 2 -2))
- (while_statement . ts-fold-range-julia)))
+ (while_statement . ts-fold-range-julia-function)
+ (comment
+ . (lambda (node offset)
+ (ts-fold-range-line-comment node offset "#")))))
(defun ts-fold-parsers-kotlin ()
"Rule set for Kotlin."
diff --git a/ts-fold-summary.el b/ts-fold-summary.el
index be9bf42443..14c4726439 100644
--- a/ts-fold-summary.el
+++ b/ts-fold-summary.el
@@ -183,8 +183,8 @@ type of content by checking the word boundary's existence."
(ts-fold-summary--generic doc-str "-"))
(defun ts-fold-summary-julia-doc (doc-str)
- "Extract summary from DOC-STR in julia."
- (ts-fold-summary--generic doc-str "\"\"\""))
+ "Extract summary from DOC-STR in Julia."
+ (ts-fold-summary--generic doc-str '("#" "\"\"\"")))
;;
;; (@* "Core" )
diff --git a/ts-fold-util.el b/ts-fold-util.el
index 0f8cd4aed8..d360369028 100644
--- a/ts-fold-util.el
+++ b/ts-fold-util.el
@@ -96,10 +96,8 @@ Like function `s-count-matches' but faster."
(defun ts-fold--get-face (obj trim)
"Return face name from OBJ.
If argument TRIM is non-nil, trim the OBJ."
- (let ((obj (if trim (string-trim obj) obj))
- (len (length obj)))
- (or (get-text-property 0 'face obj)
- (get-text-property (max 0 (1- len)) 'face obj))))
+ (let ((obj (if trim (string-trim obj) obj)))
+ (get-text-property 0 'face obj)))
(defun ts-fold--is-face (obj lst-face &optional trim)
"Return non-nil if OBJ's face is define inside list LST-FACE.
diff --git a/ts-fold.el b/ts-fold.el
index 5434a16157..8beffb9b20 100644
--- a/ts-fold.el
+++ b/ts-fold.el
@@ -770,17 +770,50 @@ more information."
(end (tsc-node-start-position end-node)))
(ts-fold--cons-add (cons beg end) offset)))
-(defun ts-fold-range-julia (node offset)
+(defun ts-fold-range-julia-function (node offset)
"Return the fold range for a NODE in Julia.
It excludes the NODE's first child and the `end' keyword. For
argument OFFSET, see function `ts-fold-range-seq' for more
information."
- (let* ((identifier (tsc-get-nth-named-child node 0))
- (end-position (byte-to-position (aref (tsc-node-range identifier) 1)))
- (start-position (byte-to-position (aref (tsc-node-range node) 0)))
- (fold-begin (1- (- end-position start-position))))
- (ts-fold-range-seq node (ts-fold--cons-add (cons fold-begin -2) offset))))
+ (when-let* ((identifier (tsc-get-nth-named-child node 0))
+ (params (tsc-get-nth-named-child node 1))
+ (beg (tsc-node-end-position params))
+ (end (tsc-node-end-position node))
+ (end (- end 3)))
+ (when ts-fold-on-next-line ; display nicely
+ (setq end (ts-fold--last-eol end)))
+ (ts-fold--cons-add (cons beg end) offset)))
+
+(defun ts-fold-range-julia-if (node offset)
+ "Define fold range for if statement in Julia.
+
+It excludes the NODE's first child and the `end' keyword. For
+argument OFFSET, see function `ts-fold-range-seq' for more
+information."
+ (when-let* ((params (car (ts-fold-find-children node "call_expression")))
+ (beg (tsc-node-end-position params))
+ (end (tsc-node-end-position node))
+ (end (- end 3)))
+ (when ts-fold-on-next-line ; display nicely
+ (setq end (ts-fold--last-eol end)))
+ (ts-fold--cons-add (cons beg end) offset)))
+
+(defun ts-fold-range-julia-let (node offset)
+ "Define fold range for let statement in Julia.
+
+It excludes the NODE's first child and the `end' keyword. For
+argument OFFSET, see function `ts-fold-range-seq' for more
+information."
+ (when-let* ((vars (ts-fold-find-children node "variable_declaration"))
+ (last-var (last vars))
+ (last-var (car last-var))
+ (beg (tsc-node-end-position last-var))
+ (end (tsc-node-end-position node))
+ (end (- end 3)))
+ (when ts-fold-on-next-line ; display nicely
+ (setq end (ts-fold--last-eol end)))
+ (ts-fold--cons-add (cons beg end) offset)))
(defun ts-fold-range-kotlin-when (node offset)
"Return the fold range for `when' NODE in Kotlin.
- [nongnu] elpa/treesit-fold e82256dd27 393/417: fix: missing treesit prefix, (continued)
- [nongnu] elpa/treesit-fold e82256dd27 393/417: fix: missing treesit prefix, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold d705c12059 299/417: feat: Add Zig support (#82), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 7a7bd70185 295/417: feat: Add VHDL support (#79), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 0c13c0e4ed 374/417: ci: Bump Emacs 29.x to 3, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold e015c9a3eb 297/417: feat: Add Jsonnet support (#81), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold d50f5dd2f8 398/417: feat(parser): Add token_tree to Rust, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 6dda55a29a 298/417: doc: Add development languages, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold ac1461d364 338/417: feat: Add LLVM support, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 9f82f1e632 400/417: Support for treesit.el (#3), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 1d8d9352a1 369/417: feat: Add Svelte support, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold c0e9bb7f3e 344/417: fix: Improve Julia rules,
ELPA Syncer <=
- [nongnu] elpa/treesit-fold 9f48ef560c 322/417: fix: render all frames, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 12ae1d0457 356/417: Added section & environment folding to latex-parser, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold ee0c0eb252 312/417: fix(make): Folding recipe, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 57c1bb8e0a 317/417: feat: Add Arduino support (#95), ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 15811f4465 386/417: fix: on fold hook in recursive open, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 9945282f03 349/417: Added a matlab parser for folding., ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold a549e4050c 367/417: chore: Test 29.2, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold c6014608c7 365/417: fix(parser): Support Assembly's block comment, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 6a57bd945d 364/417: fix(cmake): Enhance body folding, ELPA Syncer, 2024/07/01
- [nongnu] elpa/treesit-fold 0fa1378c9b 407/417: Remove dependency in `fringe-helper.el` (#7), ELPA Syncer, 2024/07/01