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: Sun, 26 Dec 2021 16:06:20 -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="8144"; 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 Sun Dec 26 22:08:18 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 1n1akZ-0001sI-UC for ged-emacs-devel@m.gmane-mx.org; Sun, 26 Dec 2021 22:08:16 +0100 Original-Received: from localhost ([::1]:35818 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n1akX-0003lg-IO for ged-emacs-devel@m.gmane-mx.org; Sun, 26 Dec 2021 16:08:13 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:38912) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n1aiu-0002S4-RS for emacs-devel@gnu.org; Sun, 26 Dec 2021 16:06:34 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:20855) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n1aip-0004CS-Jg for emacs-devel@gnu.org; Sun, 26 Dec 2021 16:06:30 -0500 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id A85FB10018E; Sun, 26 Dec 2021 16:06:24 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id DD83210000B; Sun, 26 Dec 2021 16:06:22 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1640552782; bh=TajWTue63zPN7aywCkng9DX4Z5SeUJbyK9Hen/sSBnA=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=XI6HO8GTCX1kvB2xgZDPrKACVxz2ZM7Ay7j9Lf05K6MxdlDOgqK6VMXU1SQ0R686M uz21XyhD3pLpAiNVRgNz16/doNcY7tCi9bSyZk2IF09Bslvgint9Q5cIqQ6+yjzPY9 P9WAvH+MmVPmMbn/xJVvFiiHzO3+G0eDvOOtWOjTT6BgVVBjA+CDHwQMP1DZ6V/9Y7 p5Gal1HFtVxqI9Vr2RDrazig0eRv3PhTTkJ+YzD7Pxb9Tpo+clYS4fb3cIXjldE6nm Hl3p0vdh+4IMlm7FxbKT7NDe7/myk2le80doANcOC1QGfLf17QEaaORA8/7AhvCa4O XUfBi3PsgkwYQ== Original-Received: from ceviche (unknown [216.154.30.173]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id AA17D12033F; Sun, 26 Dec 2021 16:06:22 -0500 (EST) In-Reply-To: (Nicolas P. Rougier's message of "Sat, 25 Dec 2021 19:37:34 +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:283355 Archived-At: > I would like to submit a new package to ELPA which is a minor mode for > replacing user-defined keywords with SVG generated tags (static or dynamics) > that can be activated with mouse. Tags can be generated using the svg-lib > package (a helper function is provided to ease the generation) but any valid > svg-image can be used. > > The sources are hosted at https://github.com/rougier/svg-tag-mode and > the README displays what it looks like. Added, thanks. 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 :-( See also patch below, Stefan diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..5c7e55e2bf --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.elc +/svg-tag-mode-autoloads.el +/svg-tag-mode-pkg.el diff --git a/svg-tag-mode.el b/svg-tag-mode.el index bc0c84da96..690cad80eb 100644 --- a/svg-tag-mode.el +++ b/svg-tag-mode.el @@ -128,8 +128,7 @@ "Action to be executed when the cursor enter a tag area" :type '(radio (const :tag "Edit tag" edit) (const :tag "Echo tag" echo) - (const :tag "No action" nil)) - :group 'svg-tag) + (const :tag "No action" nil))) (defcustom svg-tag-tags @@ -141,7 +140,6 @@ of a regular expression and tag can be either a svg tag previously created by `svg-tag-make' or a function that takes a string as argument and returns a tag. When tag is a function, this allows to create dynamic tags." - :group 'svg-tag :type '(repeat (cons (string :tag "Keyword") (list (sexp :tag "Tag") (sexp :tag "Command") @@ -175,6 +173,8 @@ allows to create dynamic tags." (tag (string-trim tag)) (beg (or (plist-get args :beg) 0)) (end (or (plist-get args :end) nil)) + ;; FIXME: What guarantees that `org-plist-delete' is defined at + ;; this point? (args (org-plist-delete args 'stroke)) (args (org-plist-delete args 'foreground)) (args (org-plist-delete args 'background)) @@ -193,7 +193,7 @@ allows to create dynamic tags." :background (face-background face nil 'default) args)))) -(defun svg-tag--cursor-function (win position direction) +(defun svg-tag--cursor-function (_win position direction) "This function hides the tag when cursor is over it, allowing to edit it." (let ((beg (if (eq direction 'entered) @@ -230,9 +230,11 @@ allows to create dynamic tags." (setq tag `(,tag (match-string 1)))) (setq tag ``(face nil display ,,tag - cursor-sensor-functions ,'(svg-tag--cursor-function) + cursor-sensor-functions (svg-tag--cursor-function) ,@(if ,callback '(pointer hand)) ,@(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))) @@ -240,12 +242,12 @@ allows to create dynamic tags." "This applies remove-text-properties with 'display removed from props" (apply oldfun start end (org-plist-delete props 'display) args)) -(defun svg-tag--remove-text-properties-on (args) +(defun svg-tag--remove-text-properties-on (_args) "This installs an advice around remove-text-properties" (advice-add 'remove-text-properties :around #'svg-tag--remove-text-properties)) -(defun svg-tag--remove-text-properties-off (args) +(defun svg-tag--remove-text-properties-off (_args) "This removes the advice around remove-text-properties" (advice-remove 'remove-text-properties #'svg-tag--remove-text-properties)) @@ -270,6 +272,8 @@ allows to create dynamic tags." ;; Install advices on remove-text-properties (before & after). This ;; is a hack to prevent org mode from removing SVG tags that use the ;; 'display property + ;; FIXME: Use an `:around' advice, so you can use `unwind-protect' + ;; to make sure we don't end up with the advice still applied. (advice-add 'org-fontify-meta-lines-and-blocks :before #'svg-tag--remove-text-properties-on) (advice-add 'org-fontify-meta-lines-and-blocks @@ -298,6 +302,7 @@ allows to create dynamic tags." #'svg-tag--remove-text-properties-on) (advice-remove 'org-fontify-meta-lines-and-blocks #'svg-tag--remove-text-properties-off) + ;; FIXME: Why? (remove-hook 'org-babel-after-execute-hook 'org-redisplay-inline-images) ;; Redisplay everything to hide tags