[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: New ELPA package ada-lite
From: |
Stefan Monnier |
Subject: |
Re: New ELPA package ada-lite |
Date: |
Mon, 15 Aug 2022 15:04:56 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
> 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
Re: New ELPA package ada-lite, Stephen Leake, 2022/08/17