all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Are variations such as these desired?
@ 2022-12-13  0:46 Perry Smith
  2022-12-13 12:14 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Perry Smith @ 2022-12-13  0:46 UTC (permalink / raw)
  To: emacs-devel


[-- 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 --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-12-26 16:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-13  0:46 Are variations such as these desired? Perry Smith
2022-12-13 12:14 ` 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

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.