[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ELPA: new package svg-tag-mode
From: |
Stefan Monnier |
Subject: |
Re: ELPA: new package svg-tag-mode |
Date: |
Mon, 27 Dec 2021 15:09:51 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
>> 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)