unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Stephen Leake <stephen_leake@stephe-leake.org>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: New ELPA package ada-lite
Date: Mon, 15 Aug 2022 15:04:56 -0400	[thread overview]
Message-ID: <jwvsflx2ww2.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <86y1vpfl1k.fsf@stephe-leake.org> (Stephen Leake's message of "Mon, 15 Aug 2022 10:56:07 -0700")

> I'd like to add a package ada-lite-mode to ELPA; code attached.  The
> intent is to be a mode for Ada files that's easier to install than the
> current ELPA ada-mode.

Sounds good, as long as the other ada-mode will be modified to (require
and) derive from (or extend) ada-lite.

Currently, if both ada-mode and ada-lite packages are installed and
activated, their autoloads will fight for the top spot of
`auto-mode-alist`.

A few more comments about the code:

> ;; To use ada-lite-mode for Ada files, put the following in your
> ;; emacs startup:
     ^^^^^
     Emacs


> ;; (require 'ada-lite-mode)

That shouldn't be necessary if the package is installed "the normal way".

> (defun ada-lite-font-lock-keywords ()
>   "Ada mode value for `font-lock-keywords'."
>   (list
>    (list (concat "\\_<" (regexp-opt ada-lite-keywords t) "\\_>") '(0 font-lock-keyword-face))
>    ))

I'd have split this into two to fit into the usual 80 columns.

> (defun ada-lite-syntax-propertize (start end)
>   "For `syntax-propertize-function'.
> Assign `syntax-table' properties in region START .. END.
> In particular, character constants are set to have string syntax."
>   ;; (info "(elisp)Syntax Properties")
>   ;;
>   ;; called from `syntax-propertize', inside save-excursion with-silent-modifications
>   (let ((inhibit-read-only t)
> 	(inhibit-point-motion-hooks t))

`inhibit-point-motion-hooks` is t (and obsolete) since Emacs-25.
And `inhibit-read-only` should already be t since we're within
`with-silent-modifications`.

>     (goto-char start)
>     (save-match-data

Why?

>       (while (re-search-forward
> 	      (concat
> 	       "[^[:alnum:])]\\('\\)[^'\n]\\('\\)"; 1, 2: character literal, not attribute
> 	       "\\|[^[:alnum:])]\\('''\\)"; 3: character literal '''
> 	       )
> 	      end t)
> 	;; syntax-propertize-extend-region-functions is set to
> 	;; syntax-propertize-wholelines by default. We assume no
> 	;; coding standard will permit a character literal at the
> 	;; start of a line (not preceded by whitespace).
> 	(cond
> 	 ((match-beginning 1)
> 	  (put-text-property
> 	   (match-beginning 1) (match-end 1) 'syntax-table '(7 . ?'))
> 	  (put-text-property
> 	   (match-beginning 2) (match-end 2) 'syntax-table '(7 . ?')))
> 	 ((match-beginning 3)
> 	  (put-text-property
> 	   (match-beginning 3) (1+ (match-beginning 3)) 'syntax-table '(7 . ?'))
> 	  (put-text-property
> 	   (1- (match-end 3)) (match-end 3) 'syntax-table '(7 . ?')))
> 	 )))))

I think

    (syntax-propertize-rules
     ("[^[:alnum:])]\\('\\)[^'\n]\\('\\)"
      (1 "\"'")
      (2 "\"'")
     ("[^[:alnum:])]\\('\\)'\\('\\)"
      (1 "\"'")
      (2 "\"'"))

would do basically the same, but:

- Is there a specific reason why you preferred to code it by hand
  (speed maybe?)
- The second char in "\"'" is unused (it's only used for open/close
  parentheses-like thingies).

You could merge the two into:

    (syntax-propertize-rules
     ("[^[:alnum:])]\\('\\)\\(?:'\\|[^'\n]\\)\\('\\)"
      (1 "\"")
      (2 "\""))


> (define-derived-mode ada-lite-mode prog-mode "ada-lite"

There's an autoload cookie missing here.

>   (set (make-local-variable 'syntax-propertize-function) #'ada-lite-syntax-propertize)
>   (syntax-ppss-flush-cache (point-min));; reparse with new function

Why/when have you found this explicit flush to be necessary?

>   (set (make-local-variable 'parse-sexp-ignore-comments) t)
>   (set (make-local-variable 'parse-sexp-lookup-properties) t)
>   (set 'case-fold-search t); Ada is case insensitive
>   (set 'completion-ignore-case t)
>   (set (make-local-variable 'comment-start) "--")
>   (set (make-local-variable 'comment-end) "")
>   (set (make-local-variable 'comment-start-skip) "---*[ \t]*")
>   (set (make-local-variable 'comment-multi-line) nil)

You can use `setq-local` on all of those.

> (defcustom ada-lite-server-exec nil
>   "Location of an Ada language server.
> If non-nil, should be an absolute path to an executable for the
> server; this allows specifying a development version. See
> `ada-lite-find-server' for default behaviour.")

A `defcustom` without :type is like a meringue without double cream,
(or like a churro without dulce de leche, depending on your religion).

> 		   (expand-file-name
> 		    (concat (file-name-directory gnat)
> 			    "../libexec/gnatstudio/als"))))))

Why not just

	   (expand-file-name "../libexec/gnatstudio/als"
	                     (file-name-directory gnat))))))

?

> (defun ada-lite-find-project (_dir)
>   "If ada-lite-mode, return ada-lite project.
> For `project-find-functions'"
>   (and (eq major-mode 'ada-lite-mode)

I recommend (derived-mode-p 'ada-lite-mode) instead?

> (if (featurep 'eglot)
>     (add-to-list 'eglot-server-programs (cons 'ada-lite-mode #'ada-lite-find-server))
>   (eval-after-load "eglot" '(add-to-list 'eglot-server-programs (cons 'ada-lite-mode #'ada-lite-find-server))))

AFAIK

   (with-eval-after-load 'eglot
     (add-to-list 'eglot-server-programs
                  (cons 'ada-lite-mode #'ada-lite-find-server)))

should do the same (including run the code right away if the feature
is already provided).


        Stefan




  reply	other threads:[~2022-08-15 19:04 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-15 17:56 New ELPA package ada-lite Stephen Leake
2022-08-15 19:04 ` Stefan Monnier [this message]
2022-08-16  2:25   ` Eli Zaretskii
2022-08-17  9:56     ` Stephen Leake
2022-08-17 12:04       ` Eli Zaretskii
2022-08-18  1:08         ` Stephen Leake
2022-08-18  6:33           ` Eli Zaretskii
2022-08-17  9:50   ` Stephen Leake
2022-08-17 10:56     ` Rudolf Schlatte
2022-08-17 11:49     ` Stefan Monnier
2022-08-18  1:23       ` Stephen Leake
2022-08-18  2:02         ` Stefan Monnier
2022-08-19 11:05 ` Felician Nemeth
2022-08-19 14:24   ` [SPAM UNSURE] " Stephen Leake
2023-01-05 22:53 ` Fernando Oleo Blanco
2023-01-07  0:38   ` Stephen Leake

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvsflx2ww2.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=stephen_leake@stephe-leake.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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).