Skip to content

Commit da38a23

Browse files
committed
Improve the style of some comments/docstrings
1 parent 581215f commit da38a23

File tree

6 files changed

+35
-39
lines changed

6 files changed

+35
-39
lines changed

lisp/tree-sitter--mac-load.el

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
(require 'seq)
22

3-
;; XXX: Using `require' after setting`module-file-suffix' to `.dylib' results in "Cannot open load
4-
;; file: No such file or directory, tree-sitter-dyn".
3+
;; XXX: Using `require' after setting`module-file-suffix' to `.dylib' results in
4+
;; "Cannot open load file: No such file or directory, tree-sitter-dyn".
55
;;
6-
;; XXX: Using `load' results in an error message with garbled text: "Symbol’s value as variable is
7-
;; void: Ïúíþ".
6+
;; XXX: Using `load' results in an error message with garbled text: "Symbol’s
7+
;; value as variable is void: Ïúíþ".
88
;;
99
;; Therefore, we use `module-load' directly.
1010
(defun ts--try-load-dyn (name)

lisp/tree-sitter-core.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
;;; Commentary:
99

1010
;; This file contains the core functionalities of tree-sitter.
11-
;;
11+
1212
;;; Code:
1313

1414
(unless (functionp 'module-load)

lisp/tree-sitter-extras.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
;;; Commentary:
88

99
;; This file contains extra functionalities built on top of `tree-sitter-mode'.
10-
;;
10+
1111
;;; Code:
1212

1313
(require 'tree-sitter)

lisp/tree-sitter-load.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
;; This file implements functions to search, load and register `tree-sitter'
1010
;; language objects (grammars).
11-
;;
11+
1212
;;; Code:
1313

1414
(require 'map)

lisp/tree-sitter-query.el

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,26 @@
33
;; Copyright (C) 2020 Tuấn-Anh Nguyễn
44
;;
55
;; Author: Jorge Javier Araya Navarro <[email protected]>
6-
;; Homepage: https://github.com/ubolonton/emacs-tree-sitter
7-
;; Version: 0.4.0
8-
;; Package-Requires: ((emacs "25.1"))
9-
;; License: MIT
106

117
;;; Commentary:
128

13-
;; This file contains other debug utilities for building queries and see
14-
;; results in a target buffer
9+
;; This file contains other debug utilities for building queries and see results
10+
;; in a target buffer.
1511

16-
;; Code:
12+
;;; Code:
1713

1814
(require 'scheme)
19-
(require 'cl-lib)
2015
(require 'tree-sitter)
2116

17+
(eval-when-compile
18+
(require 'cl-lib))
19+
2220
(defgroup tree-sitter-query nil
23-
"tree-sitter playground for GNU Emacs."
21+
"Tree-Sitter playground."
2422
:group 'tree-sitter)
2523

2624
(define-derived-mode tree-sitter-query-mode prog-mode "ts-query-builder"
27-
"Major mode for building tree-sitter queries and testing them live"
25+
"Major mode for building tree-sitter queries and testing them live."
2826
:syntax-table scheme-mode-syntax-table
2927
:abbrev-table scheme-mode-abbrev-table)
3028

@@ -38,49 +36,47 @@
3836
'((t :foreground "#000"
3937
:background "#00bfff"
4038
:weight bold))
41-
"face for match highlight"
39+
"Face for highlight captures in matches."
4240
:group 'tree-sitter-query)
4341

4442
(defun tree-sitter-query--highlight-capture (capture)
45-
"Highlight a CAPTURE match in the current buffer."
43+
"Highlight CAPTURE in the current buffer."
4644
(pcase-let* ((`(,capture-name . ,captured-node) capture)
4745
(`(,node-start . ,node-end) (ts-node-position-range captured-node))
48-
(overlay-added (make-overlay node-start node-end)))
49-
;; ensure it is deleted automatically when the overlay becomes empty
50-
(overlay-put overlay-added 'evaporate t)
51-
;; set the match-face as the face of the overlay
52-
(overlay-put overlay-added 'face 'tree-sitter-query-match)
53-
;; put the name of the capture in the help-echo, if any
46+
(overlay (make-overlay node-start node-end)))
47+
;; Ensure the overlay is deleted when it becomes empty.
48+
(overlay-put overlay 'evaporate t)
49+
(overlay-put overlay 'face 'tree-sitter-query-match)
50+
;; Use the capture's name as the mouseover tooltip.
5451
(unless (string= capture-name "")
55-
(overlay-put overlay-added 'help-echo capture-name))))
52+
(overlay-put overlay 'help-echo capture-name))))
5653

5754
(defun tree-sitter-query--eval-query (patterns)
58-
"Evaluate a query PATTERNS against the target buffer."
55+
"Evaluate query PATTERNS against the target buffer."
5956
(with-current-buffer tree-sitter-query--target-buffer
60-
;; clean the target buffer of overlays
6157
(remove-overlays)
6258
(let* ((query (ts-make-query tree-sitter-language patterns))
6359
(root-node (ts-root-node tree-sitter-tree))
6460
(captures-list (ts-query-captures query root-node)))
6561
(if (= (length captures-list) 0)
66-
(message "no matches found")
67-
;; iterate all matches and highlight them with an underline
62+
(message "No matches found")
63+
;; Highlight captures.
6864
(cl-loop
6965
for captures across captures-list
7066
do
7167
(cl-loop
7268
for capture on captures
7369
do (tree-sitter-query--highlight-capture capture)))))))
7470

75-
(defun tree-sitter-query--after-change (&rest args)
76-
"Run evaluation of pattern in current buffer for every change made by the user, ignoring ARGS."
71+
(defun tree-sitter-query--after-change (&rest _args)
72+
"Run query patterns against the target buffer and update highlighted texts."
7773
(with-current-buffer (get-buffer tree-sitter-query-builder-buffer-name)
78-
(let ((pattern (buffer-string)))
74+
(let ((patterns (buffer-string)))
7975
(with-demoted-errors "Error: %S"
80-
(tree-sitter-query--eval-query pattern)))))
76+
(tree-sitter-query--eval-query patterns)))))
8177

8278
(defun tree-sitter-query--clean-target-buffer ()
83-
"Remove all overlays if the builder buffer happens to be killed."
79+
"Remove all overlays from the target buffer."
8480
(with-current-buffer tree-sitter-query--target-buffer
8581
(remove-overlays))
8682
(setq tree-sitter-query--target-buffer nil))
@@ -89,7 +85,7 @@
8985
(defun tree-sitter-query-builder ()
9086
"Provide means for developers to write and test tree-sitter queries.
9187
92-
The buffer on focus when the command is called is set as the target buffer"
88+
The buffer on focus when the command is called is set as the target buffer."
9389
(interactive)
9490
(let* ((target-buffer (current-buffer))
9591
(builder-buffer (get-buffer-create tree-sitter-query-builder-buffer-name))
@@ -113,7 +109,7 @@ The buffer on focus when the command is called is set as the target buffer"
113109
(add-hook 'after-change-functions 'tree-sitter-query--after-change nil :local)
114110
(add-hook 'kill-buffer-hook 'tree-sitter-query--clean-target-buffer nil :local))
115111
(setf tree-sitter-query--target-buffer target-buffer)
116-
;; switch focus to the query builder window
112+
;; Switch focus to the query builder window.
117113
(select-window (get-buffer-window builder-buffer))))
118114

119115
(provide 'tree-sitter-query)

lisp/tree-sitter.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
;;; Commentary:
1313

1414
;; This is an Emacs binding for tree-sitter, an incremental parsing system
15-
;; (https://tree-sitter.github.io/tree-sitter/). It includes both the core APIs, and a minor mode
16-
;; that provides a buffer-local up-to-date syntax tree.
15+
;; (https://tree-sitter.github.io/tree-sitter/). It includes both the core APIs,
16+
;; and a minor mode that provides a buffer-local up-to-date syntax tree.
1717

1818
;;; Code:
1919

0 commit comments

Comments
 (0)