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: ELPA: new package svg-tag-mode Date: Mon, 27 Dec 2021 15:09:51 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6735"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: "Nicolas P. Rougier (inria)" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Dec 27 21:13:27 2021 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 1n1wN5-0001an-7v for ged-emacs-devel@m.gmane-mx.org; Mon, 27 Dec 2021 21:13:27 +0100 Original-Received: from localhost ([::1]:42092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n1wN2-0000XT-Uj for ged-emacs-devel@m.gmane-mx.org; Mon, 27 Dec 2021 15:13:24 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:42308) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n1wJi-0007aw-Td for emacs-devel@gnu.org; Mon, 27 Dec 2021 15:10:01 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:58962) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n1wJg-0001c4-97 for emacs-devel@gnu.org; Mon, 27 Dec 2021 15:09:58 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 0323780602; Mon, 27 Dec 2021 15:09:54 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 86B0180198; Mon, 27 Dec 2021 15:09:52 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1640635792; bh=C9Ex6Z280BD8sl12Zjybhd5NsfYIUWAiQM4oLpanO00=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=PnC8blkVT4lcVnxmTs/Qmmw9FZZXllCoNhpc5/Oo3FAHGgm6NB273o7PT8FNLMGAN qUIrpKH88He2DOr7Nq8eJ3FtiOBe/5DC3d6Y6vi3O53W5x4uqA6S2fxDBEQZFZ8BP/ DsvbF5S0AWHXf/BsEPOgbJUz05JOI8/Pf2w8PZj703kr8FSqs0of9IDvhTMmErOObg 8uomejbsD79Z0jJwPY5My/qZVVeUY4Oh6D3pLRvG48tS9KrFBpuvEHqySolhsLbHT0 jkwIBEbVnJCBVcD9jEHayapl74OAB9YGBpNCSjJQ+dwxKeuTk4kcJ6lduHIUq+ZOJx 6CsVn3lR8sKkA== Original-Received: from pastel (unknown [216.154.30.173]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 4AB32120254; Mon, 27 Dec 2021 15:09:52 -0500 (EST) In-Reply-To: (Nicolas P. Rougier's message of "Mon, 27 Dec 2021 08:34:44 +0100") 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 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:283449 Archived-At: >> The `svg-tag-tags` structure (and the provided examples) encourages the >> use of code-hidden-inside-data, i.e. code that will never be exposed >> to things like flymake or the byte-compiler :-( > > You mean there might be a better structure or is the whole concept "flawed"? Not sure if there's a much better option, but I'd suggest you use backquote+unquotes in your examples as in ;; (setq svg-tag-tags ;; `(("\\(:[A-Z]+:\\)" . (,(lambda (tag) ;; (svg-tag-make tag :beg 1 :end -1)))))) and avoid "expressions", i.e. prefer ;; (setq svg-tag-tags ;; `((":HELLO:" ,(lambda (_tag) (svg-tag-make "HELLO")) ;; ,(lambda () (interactive) (message "Hello world!")) ;; "Print a greeting message")))) over ;; (setq svg-tag-tags ;; '((":HELLO:" . ((svg-tag-make "HELLO") ;; (lambda () (interactive) (message "Hello world!")) ;; "Print a greeting message")))) would you could even disallow, as in the patch below. >> ,@(if ,help `(help-echo ,,help)) >> + ;; FIXME: Don't hard-code the internal representation >> + ;; of keymaps. >> ,@(if ,callback `(keymap (keymap (mouse-1 >> . ,,callback)))))) >> `(,pattern 1 ,tag))) > > I had a hard time to make this to work and I did not find a proper solution > with the use of a local sparse keymap (maybe there's an obvious solution but > I get lost with `` and ,,). What would be a clean solution? I hate double backquotes so I'd recommend rewriting the code to avoid them, but the patch below might get you started. Stefan diff --git a/svg-tag-mode.el b/svg-tag-mode.el index cf2c236bb9..668570dede 100644 --- a/svg-tag-mode.el +++ b/svg-tag-mode.el @@ -234,11 +234,13 @@ allows to create dynamic tags." (let* ((pattern (if (string-match "\\\\(.+\\\\)" (car item)) (car item) (format "\\(%s\\)" (car item)))) - (tag (nth 0 (cdr item))) + (tag `(funcall ',(nth 0 (cdr item)) (match-string 1))) (callback (nth 1 (cdr item))) + (map (when callback + (let ((map (make-sparse-keymap))) + (define-key map [mouse-1] callback) + map))) (help (nth 2 (cdr item)))) - (when (or (functionp tag) (and (symbolp tag) (fboundp tag))) - (setq tag `(,tag (match-string 1)))) (setq tag ``(face nil display ,,tag cursor-sensor-functions (svg-tag--cursor-function) @@ -246,7 +248,7 @@ allows to create dynamic tags." ,@(if ,help `(help-echo ,,help)) ;; FIXME: Don't hard-code the internal representation ;; of keymaps. - ,@(if ,callback `(keymap (keymap (mouse-1 . ,,callback)))))) + ,@',(if map `(keymap ,map)))) `(,pattern 1 ,tag))) (defun svg-tag--remove-text-properties (oldfun start end props &rest args)