[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/zig-mode 8f59f86 089/104: Implement beginning/end-of-defun
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/zig-mode 8f59f86 089/104: Implement beginning/end-of-defun |
Date: |
Sun, 29 Aug 2021 11:37:08 -0400 (EDT) |
branch: elpa/zig-mode
commit 8f59f86133983975f1d25aefaf7378616c401a1d
Author: ventlark <ventlark@gmail.com>
Commit: ventlark <ventlark@gmail.com>
Implement beginning/end-of-defun
This allows us to use C-M-a and C-M-e to navigate by function blocks.
Also includes test, const, and export blocks that contain a brace.
---
zig-mode.el | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/zig-mode.el b/zig-mode.el
index db9a03b..4e0900b 100644
--- a/zig-mode.el
+++ b/zig-mode.el
@@ -264,6 +264,67 @@ If given a SOURCE, execute the CMD on it."
;; Skip backwards past whitespace and comment end delimiters.
(/= 0 (skip-syntax-backward " >")))))
+(defun zig-in-str-or-cmnt () (nth 8 (syntax-ppss)))
+(defconst zig-top-item-beg-re
+ (concat "^"
+ (regexp-opt
+ '("const" "pub" "fn" "extern" "export" "test"))
+ "[[:space:]]+"
+ ".*{")
+ "Start of a Zig item.")
+
+(defun zig-beginning-of-defun (&optional arg)
+ "Move backward to the beginning of the current defun.
+
+With ARG, move backward multiple defuns. Negative ARG means
+move forward.
+
+This is written mainly to be used as `beginning-of-defun-function' for Zig."
+ (interactive "p")
+ (let* ((arg (or arg 1))
+ (magnitude (abs arg))
+ (sign (if (< arg 0) -1 1)))
+ ;; If moving forward, don't find the defun we might currently be
+ ;; on.
+ (when (< sign 0)
+ (end-of-line))
+ (catch 'done
+ (dotimes (_ magnitude)
+ ;; Search until we find a match that is not in a string or comment.
+ (while (if (re-search-backward (concat "^\\(" zig-top-item-beg-re
"\\)")
+ nil 'move sign)
+ (zig-in-str-or-cmnt)
+ ;; Did not find it.
+ (throw 'done nil)))))
+ t)
+ (beginning-of-line))
+
+(defun zig-end-of-defun ()
+ "Move forward to the next end of defun.
+
+With argument, do it that many times.
+Negative argument -N means move back to Nth preceding end of defun.
+
+Assume that this is called after `beginning-of-defun'. So point is
+at the beginning of the defun body.
+
+This is written mainly to be used as `end-of-defun-function' for Zig."
+ (interactive)
+ ;; Find the opening brace
+ (if (re-search-forward "[{]" nil t)
+ (progn
+ (goto-char (match-beginning 0))
+ ;; Go to the closing brace
+ (condition-case nil
+ (forward-sexp)
+ (scan-error
+ ;; The parentheses are unbalanced; instead of being unable
+ ;; to fontify, just jump to the end of the buffer
+ (goto-char (point-max))))
+ (end-of-line))
+ ;; There is no opening brace, so consider the whole buffer to be one
"defun"
+ (goto-char (point-max))))
+
(defun zig-mode-indent-line ()
(interactive)
;; First, calculate the column that this line should be indented to.
@@ -428,6 +489,8 @@ If given a SOURCE, execute the CMD on it."
(append zig-electric-indent-chars
(and (boundp 'electric-indent-chars)
electric-indent-chars)))
+ (setq-local beginning-of-defun-function 'zig-beginning-of-defun)
+ (setq-local end-of-defun-function 'zig-end-of-defun)
(setq-local indent-line-function 'zig-mode-indent-line)
(setq-local indent-tabs-mode nil) ; Zig forbids tab characters.
(setq-local syntax-propertize-function 'zig-syntax-propertize)
- [nongnu] branch elpa/zig-mode created (now acf3ee8), ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 9bdc960 025/104: Support multiline string literals (#8), ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode b410d5a 031/104: Add AppVeyor config, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode f26f5d0 033/104: Add "Testing" and "License" sections to README.md, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode b0eb489 051/104: [+] Guarantee Unix line endings to avoid compiler complaining with DOS carriage return, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 32aec72 064/104: Add previous-line doc comments, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 8df4efd 078/104: Merge pull request #33 from joachimschmidt557/use-rx, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 6a3522f 084/104: Merge pull request #45 from joachimschmidt557/revert-rx, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 88b429d 083/104: Merge pull request #46 from travv0/master, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 8f59f86 089/104: Implement beginning/end-of-defun,
ELPA Syncer <=
- [nongnu] elpa/zig-mode 9ad0ccf 008/104: Indentation is 4 spaces by default., ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode ff0bc79 006/104: Full symbols., ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 814657c 018/104: Update syntax, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode a4f1e11 022/104: Just disable syntactic indentation (it's broken), ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 51a99d1 023/104: Add alternate install instructions to the README (#9), ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode cb485ff 034/104: Added anyerror keyword, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 1f4ebf1 035/104: section -> linksection, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 3cac32b 040/104: Drop #' since it's redundant, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode ab655a9 043/104: Add Commentary, ELPA Syncer, 2021/08/29
- [nongnu] elpa/zig-mode 1552e0e 058/104: Merge pull request #20 from mgxm/feat/add_zig_cli_integration, ELPA Syncer, 2021/08/29