From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: casouri@gmail.com, 59662@debbugs.gnu.org
Subject: bug#59662: 29.0.50; [PATCH] Add treesit--indent-defun
Date: Fri, 02 Dec 2022 19:32:33 +0100 [thread overview]
Message-ID: <87359x8xmm.fsf@thornhill.no> (raw)
In-Reply-To: <834judg67m.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 1398 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Theodor Thornhill <theo@thornhill.no>
>> Cc: casouri@gmail.com, 59662@debbugs.gnu.org
>> Date: Fri, 02 Dec 2022 16:06:46 +0100
>>
>> > Why in lisp.el? we are talking about a feature of C-like languages. The
>> > current binding of "C-c C-q" is in cc-cmds.el, so what I had in mind is to
>> > have its counterpart in c-ts-mode.el.
>>
>> Something like this?
>
> Yes, thanks.
>
> But a command should not have "--" in its name, since every command is by
> definition a public function, not an internal one.
That makes sense. I was in doubt about that, but decided to go the
(wrong) direction. Updated in latest patch.
However - mark-defun signals an error on some constructs because of
number-or-marker error:
Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
treesit-end-of-defun()
c-ts-mode--end-of-defun()
end-of-defun()
mark-defun(1 nil)
mark-defun(1 23209)
funcall-interactively(mark-defun 1 23209)
call-interactively(mark-defun record nil)
command-execute(mark-defun record)
execute-extended-command(nil "mark-defun" nil)
funcall-interactively(execute-extended-command nil "mark-defun" nil)
call-interactively(execute-extended-command nil nil)
command-execute(execute-extended-command)
I'll file a separate bug report for this one, if that's ok? Yuan, are
you ok with this patch?
Theo
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-c-ts-mode-indent-defun.patch --]
[-- Type: text/x-diff, Size: 1452 bytes --]
From b7c82cf11404a68338aa495cbd4424f45e1f8405 Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <theo@thornhill.no>
Date: Fri, 2 Dec 2022 16:05:35 +0100
Subject: [PATCH] Add c-ts-mode-indent-defun
Add in this function to mimic 'c-indent-defun'
* lisp/progmodes/c-ts-mode.el (c-ts-mode-indent-defun): New function.
(c-ts-mode-map): New mode map that uses said function.
---
lisp/progmodes/c-ts-mode.el | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index fcabb5beac..36d67c5701 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -518,9 +518,25 @@ c-ts-mode--end-of-defun
(if (looking-at "\\s<\\|\n")
(forward-line 1)))))
+(defun c-ts-mode-indent-defun ()
+ "Indent the current top-level declaration syntactically.
+
+`treesit-defun-type-regexp' defines what constructs to indent."
+ (interactive)
+ (save-excursion
+ (mark-defun)
+ (indent-region (region-beginning) (region-end))))
+
+(defvar-keymap c-ts-mode-map
+ :doc "Keymap for the C language with tree-sitter"
+ :parent prog-mode-map
+ "C-c C-q" #'c-ts-mode-indent-defun)
+
;;;###autoload
(define-derived-mode c-ts-base-mode prog-mode "C"
- "Major mode for editing C, powered by tree-sitter."
+ "Major mode for editing C, powered by tree-sitter.
+
+\\{c-ts-mode-map}"
:syntax-table c-ts-mode--syntax-table
;; Navigation.
--
2.34.1
next prev parent reply other threads:[~2022-12-02 18:32 UTC|newest]
Thread overview: 97+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-28 19:32 bug#59662: 29.0.50; [PATCH] Add treesit--indent-defun Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
[not found] ` <handler.59662.B.16696639455818.ack@debbugs.gnu.org>
2022-11-29 6:10 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-29 12:01 ` Eli Zaretskii
2022-11-29 12:14 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-29 14:15 ` Eli Zaretskii
2022-11-30 10:33 ` Yuan Fu
2022-11-30 23:23 ` Yuan Fu
2022-12-01 1:07 ` Yuan Fu
2022-12-01 7:19 ` Eli Zaretskii
2022-12-01 6:10 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-01 7:13 ` Eli Zaretskii
2022-12-01 7:22 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-01 7:48 ` Eli Zaretskii
2022-12-01 8:13 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-02 15:06 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-02 15:45 ` Eli Zaretskii
2022-12-02 18:32 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-12-02 18:52 ` Eli Zaretskii
2022-12-02 19:02 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-02 20:24 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-02 21:09 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-02 21:19 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-04 12:33 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-04 12:40 ` Eli Zaretskii
2022-12-07 9:31 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-07 13:44 ` Eli Zaretskii
2022-12-02 19:53 ` Dmitry Gutov
2022-12-02 20:01 ` Dmitry Gutov
2022-12-02 20:07 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-02 22:27 ` Dmitry Gutov
2022-12-03 6:47 ` Eli Zaretskii
2022-12-03 15:59 ` Dmitry Gutov
2022-12-03 17:54 ` Eli Zaretskii
2022-12-08 1:37 ` Dmitry Gutov
2022-12-08 7:16 ` Eli Zaretskii
2022-12-08 8:11 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-08 8:27 ` Eli Zaretskii
2022-12-08 8:56 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-08 9:08 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-08 10:39 ` Eli Zaretskii
2022-12-08 11:09 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-08 11:38 ` Eli Zaretskii
2022-12-08 14:22 ` Dmitry Gutov
2022-12-08 14:58 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-08 16:06 ` Dmitry Gutov
2022-12-08 16:33 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-08 22:03 ` Dmitry Gutov
2022-12-08 14:18 ` Dmitry Gutov
2022-12-08 14:53 ` Eli Zaretskii
2022-12-08 15:43 ` Dmitry Gutov
2022-12-08 16:04 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-08 16:23 ` Dmitry Gutov
2022-12-08 19:15 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-08 19:50 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-08 20:12 ` Eli Zaretskii
2022-12-08 21:21 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-09 5:06 ` Eli Zaretskii
2022-12-09 13:24 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-09 13:38 ` Dmitry Gutov
2022-12-09 14:46 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-09 14:56 ` Dmitry Gutov
2022-12-09 15:13 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-09 15:27 ` Dmitry Gutov
2022-12-09 15:29 ` Dmitry Gutov
2022-12-09 15:50 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-09 16:05 ` Dmitry Gutov
2022-12-09 19:15 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-09 20:28 ` Dmitry Gutov
2022-12-09 20:31 ` Dmitry Gutov
2022-12-09 20:20 ` Eli Zaretskii
2022-12-09 20:30 ` Dmitry Gutov
2022-12-10 14:04 ` Eli Zaretskii
2022-12-10 19:25 ` Dmitry Gutov
2022-12-09 21:09 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-10 12:02 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-10 14:27 ` Eli Zaretskii
2022-12-10 14:09 ` Eli Zaretskii
2022-12-10 20:21 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-11 8:11 ` Eli Zaretskii
2022-12-11 8:39 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-11 10:03 ` Eli Zaretskii
2022-12-11 14:13 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-11 20:36 ` Dmitry Gutov
2022-12-11 20:39 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-08 22:05 ` Dmitry Gutov
2022-12-08 22:10 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-08 22:49 ` Dmitry Gutov
2022-12-08 14:24 ` Dmitry Gutov
2022-12-08 15:37 ` Dmitry Gutov
2022-12-08 15:46 ` Eli Zaretskii
2022-12-07 19:54 ` Yuan Fu
2022-12-07 20:06 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-07 21:40 ` Yuan Fu
2022-12-07 21:53 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-07 23:09 ` Yuan Fu
2022-12-08 6:02 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-07 23:01 ` Yuan Fu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87359x8xmm.fsf@thornhill.no \
--to=bug-gnu-emacs@gnu.org \
--cc=59662@debbugs.gnu.org \
--cc=casouri@gmail.com \
--cc=eliz@gnu.org \
--cc=theo@thornhill.no \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.