From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: New ELPA package ada-lite Date: Mon, 15 Aug 2022 15:04:56 -0400 Message-ID: References: <86y1vpfl1k.fsf@stephe-leake.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5991"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: emacs-devel To: Stephen Leake Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Aug 15 21:18:34 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oNfbd-0001FJ-BO for ged-emacs-devel@m.gmane-mx.org; Mon, 15 Aug 2022 21:18:33 +0200 Original-Received: from localhost ([::1]:51170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNfbb-00087X-Un for ged-emacs-devel@m.gmane-mx.org; Mon, 15 Aug 2022 15:18:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38526) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNfOb-0004P0-Rs for emacs-devel@gnu.org; Mon, 15 Aug 2022 15:05:18 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:55388) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNfOY-0006ah-GQ for emacs-devel@gnu.org; Mon, 15 Aug 2022 15:05:04 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 95E6880636; Mon, 15 Aug 2022 15:04:59 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 9D31A80172; Mon, 15 Aug 2022 15:04:57 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1660590297; bh=ORTIZ+IZwfPBkxbAr6w7k+C068dgkePgnCYg7nF9C1Y=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=le3kW2CPT9Ou+mrJ6cbepBE8fN48eOtfLkFArM75SC1pBRvWqzLJL2VIS8IkAiUl+ jE9EoxbVkoVj5z9hhPYbRcmYcFLM+AWarK8PlaZ9OW/aY0DF6qCci5389BNrYSVJ3Z i6F4hS4Si4LzY0ulXPMVmUFmkGHmaLVGeUBpF9QJKogVRAE0OK6DX3mUqIRgkQxate GBrlaoAKvxvVX05ShYwo8pBMnTLJzUneffU5Oc/lAia4g6n72ROBFfPc79BAJbbaY7 wQpGuff52q447PKc5TTfUvVDcNCTxTwiQ6XoV0qe11ZTfgi5lN5YpvWbDgYWmv+KG8 6XDc6FzQiK0vg== Original-Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 7465D12047E; Mon, 15 Aug 2022 15:04:57 -0400 (EDT) In-Reply-To: <86y1vpfl1k.fsf@stephe-leake.org> (Stephen Leake's message of "Mon, 15 Aug 2022 10:56:07 -0700") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:293488 Archived-At: > 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