all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Perry Smith <pedz@easesoftware.com>
To: emacs-devel <emacs-devel@gnu.org>
Subject: Are variations such as these desired?
Date: Mon, 12 Dec 2022 18:46:29 -0600	[thread overview]
Message-ID: <668E5804-C241-4D72-8FC6-4F1B8454917E@easesoftware.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 2378 bytes --]

Adding on to the ruby-ts-mode I thought I would point out an example of the type of power available with tree sitter.

With a not so complex function:

(defun my-func ( node parent &rest _)
  "Proof of concept to do right justification of NODE and PARENT."
  (message "here %s" (treesit-node-text node))
  (let* ((children (treesit-node-children parent t))
         (open-bracket (nth 0 (treesit-node-children parent nil)))
         (first-child (nth 0 children))
         (same-line (equal (line-number-at-pos (treesit-node-start open-bracket))
                           (line-number-at-pos (treesit-node-start first-child))))
         (max-length (apply #'max (mapcar (lambda ( child )
                                            (- (treesit-node-end child) (treesit-node-start child)))
                                          children)))
         (node-length (- (treesit-node-end node) (treesit-node-start node)))
         (grand-parent-bol (save-excursion
                             (goto-char (treesit-node-start (treesit-node-parent parent)))
                             (back-to-indentation)
                             (point)))
         (align-column (if same-line
                           (- (+ (treesit-node-end open-bracket) max-length 1) ruby-ts-mode-indent-offset)
                         (+ grand-parent-bol max-length 1))))

    (- align-column node-length)))

And two indent rules:

           ((query "(array \"[\" ( (_) ( \",\" (_) )*) @indent \",\"? \"]\")") my-func ruby-ts-mode-indent-offset)
           ((n-p-gp "]" "array" "assignment") grand-parent ruby-ts-mode-indent-offset)

The programmer can now right justify elements of an array in two different fashions:


if dog
  array = [
       145,
     21110,
        11
    ]
end

if dog
  array = [   145,
            21110,
               11]
end

The two rules could be conditionally added to the rest of the rules via a customizable boolean variable such as ruby-ts-mode--right-justify-arrays (for example).

And this concept could be applied to hashes.  The possibilities are almost endless.

My question is, do others see adding this versatility at this point in time to the Emacs distribution as desirable?  Should we wait and see how users use the new system?  Perhaps some see both of the above formats as abominations.

Perry


[-- Attachment #1.2: Type: text/html, Size: 7164 bytes --]

[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

             reply	other threads:[~2022-12-13  0:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-13  0:46 Perry Smith [this message]
2022-12-13 12:14 ` Are variations such as these desired? Eli Zaretskii
2022-12-13 13:18   ` Perry Smith
2022-12-13 14:36 ` Stefan Monnier
2022-12-13 14:50   ` Perry Smith
2022-12-13 15:18     ` Stefan Monnier
2022-12-26 16:19 ` Dmitry Gutov

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=668E5804-C241-4D72-8FC6-4F1B8454917E@easesoftware.com \
    --to=pedz@easesoftware.com \
    --cc=emacs-devel@gnu.org \
    /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.