all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Gabriel Santos <gabrielsantosdesouza@disroot.org>
Cc: dev@rjt.dev, Eli Zaretskii <eliz@gnu.org>, 74461@debbugs.gnu.org
Subject: bug#74461: [PATCH] Add go-work-ts-mode
Date: Sat, 21 Dec 2024 22:10:54 -0500	[thread overview]
Message-ID: <jwva5coctia.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <877c8l55he.fsf@disroot.org> (Gabriel Santos's message of "Sat, 30 Nov 2024 08:24:45 -0300")

> --- a/lisp/progmodes/eglot.el
> +++ b/lisp/progmodes/eglot.el
> @@ -273,7 +273,7 @@ automatically)."
>      (elm-mode . ("elm-language-server"))
>      (mint-mode . ("mint" "ls"))
>      ((kotlin-mode kotlin-ts-mode) . ("kotlin-language-server"))
> -    ((go-mode go-dot-mod-mode go-dot-work-mode go-ts-mode go-mod-ts-mode)
> +    ((go-mode go-dot-mod-mode go-dot-work-mode go-ts-mode go-mod-ts-mode go-work-ts-mode)
>       . ("gopls"))
>      ((R-mode ess-r-mode) . ("R" "--slave" "-e"
>                              "languageserver::run()"))

Do we have a way to tell Eglot which LSP server(s) to use via some
buffer-local var, instead of having to change this centralized
"database"?

> @@ -565,6 +568,102 @@ what the parent of the node would be if it were a node."
>  (if (treesit-ready-p 'gomod)
>      (add-to-list 'auto-mode-alist '("/go\\.mod\\'" . go-mod-ts-mode)))
>  
> +;; go.work support.

I'd use 3 or more semi-colons here, so it acts as a section separator.

> +(defvar go-work-ts-mode--syntax-table
> +  (let ((table (make-syntax-table)))
> +    (modify-syntax-entry ?/   ". 124b" table)
> +    (modify-syntax-entry ?\n  "> b"    table)
> +    table)
> +  "Syntax table for `go-work-ts-mode'.")

The "4" above is weird since there's no "3".  Similarly, the use of "b"
is a bit odd since the "normal" comment is unused.

> +(defun go-work-ts-mode--in-directive-p ()
> +  "Return non-nil if point is inside a Go workspace directive.

This docstring doesn't seem right: the function returns another
function, not a boolean.

> +        (pcase (treesit-node-type (treesit-node-at (point)))
> +          ("replace" t)
> +          ("use" t))))))

AKA (member (treesit-node-type (treesit-node-at (point))) '("replace" "use"))

> +;;;###autoload
> +(define-derived-mode go-work-ts-mode prog-mode "Go Work"
> +  "Major mode for editing go.work files, powered by tree-sitter."
> +  :group 'go
> +  :syntax-table go-work-ts-mode--syntax-table

Why not use the standard name for the syntax-table (in which case you
don't even need this `:syntax-table` argument)?

> +    ;; Indent.
> +    (setq-local indent-tabs-mode t
> +                treesit-simple-indent-rules go-work-ts-mode--indent-rules)

Is this `indent-tabs-mode` setting required by the definition of the
go.work syntax/language, or is it a personal preference?  If it's
a personal preference then it doesn't belong in the major mode, and if
it's required by the syntax, then say so in a comment (ideally with
a URL pointing to the relevant part of the language definition).

> +(if (treesit-ready-p 'gowork)
> +    (add-to-list 'auto-mode-alist '("/go\\.work\\'" . go-work-ts-mode)))

Since we don't have another (non-treesitter) mode for these files, I'd
recommend you go straight for:

    ;;;###autoload
    (add-to-list 'auto-mode-alist '("/go\\.work\\'" . go-work-ts-mode))


- Stefan






  parent reply	other threads:[~2024-12-22  3:10 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-21 10:49 bug#74461: [PATCH] Add go-work-ts-mode Gabriel Santos via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-21 16:02 ` Eli Zaretskii
     [not found]   ` <F23F09F1-D3C4-4133-AC46-67E7E1C35BDA@disroot.org>
2024-11-21 19:14     ` Eli Zaretskii
2024-11-22  0:13 ` Gabriel Santos via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-22  2:36 ` Randy Taylor
2024-11-22 10:15 ` Gabriel Santos via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-30 10:17   ` Eli Zaretskii
2024-11-30 11:24     ` Gabriel Santos via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-01 20:42       ` Randy Taylor
2024-12-01 23:00         ` Gabriel Santos via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-22  3:10       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-12-22 11:32         ` Gabriel Santos via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-22 12:12           ` Gabriel Santos via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-18 22:57 ` Gabriel Santos via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-22  2:33 ` bug#74461: [PACH] " Gabriel Santos via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-22  7:04   ` Eli Zaretskii

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=jwva5coctia.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=74461@debbugs.gnu.org \
    --cc=dev@rjt.dev \
    --cc=eliz@gnu.org \
    --cc=gabrielsantosdesouza@disroot.org \
    --cc=monnier@iro.umontreal.ca \
    /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.