bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#64584: 29.0.91; skeleton: cannot pass `str' as argument to some func


From: Visuwesh
Subject: bug#64584: 29.0.91; skeleton: cannot pass `str' as argument to some functions
Date: Tue, 12 Sep 2023 08:06:25 +0530
User-agent: Gnus/5.13 (Gnus v5.13)

[திங்கள் செப்டம்பர் 11, 2023] Stefan Monnier wrote:

>>> It should work if you can change your skeleton to something like:
>>>
>>>     (define-skeleton test-skeleton ""
>>>       (file-relative-name (read-file-name "P: "))
>>>       str
>>>       (shell-quote-argument str))
>>>
>>> where that first use of `str` will convert it from something that "read
>>> a string according to INTERACTOR" to the actual string.
>>
>> ... this inserts the directory twice.  :-(
>
> Of course, it changes the behavior of your skeleton.
> I assumed that your *real* skeleton does something else anyway, so
> I showed what kind of change might help.
>
> To do what your above skeleton does, you simply can't use `str`.
> You need something like:
>
>     (define-skeleton test-skeleton ""
>       nil
>       (shell-quote-argument (file-relative-name (read-file-name "P: "))))
>
> instead.

Yes, of course.  I end up having to do something like the let form below

    (defun vz/read-relative-filename (&optional prompt dir)
      (let ((file (read-file-name (or prompt "Filname: ") dir "")))
         (if (equal file "")
             ""
           (file-relative-name file default-directory))))

    (define-skeleton imagemagick-collage-images
      "Collage/montage multiple images using imagemagick."
      nil
      "montage "
      ((let ((file (vz/read-relative-filename "Image: ")))
         (if (equal file "")
             ""
           (shell-quote-argument file)))
       str " ")
      "-geometry 00 "
      "-tile " (skeleton-read "How many columns (horizontal)? ") "x"
      (skeleton-read "How many rows (vertical)? ")
      (shell-quote-argument (vz/read-relative-filename "Out: ")))

I was hoping I could avoid doing this.  I wanted to ask you why the eval
form used by skeleton errors but now I realise that str is a list when
it is eval'ed in the example I gave in the OP; I was thinking of eval as
some kind of macroexpansion instead.  I disturbed you all for nothing,
sorry.

I can do

    (define-skeleton test
      ""
      (read-file-name "p: ")
      (shell-quote-argument (eval str)))

instead and that works without the error.  I do wonder if the eval can
be avoided but this bug can be closed regardless.

>> AFAIU, using 'str should prevent the insertion of the value but that
>> signals the same error.
>
> Sorry, I don't know what you mean by that.

I meant this part in skeleton-insert's docstring

    Quoted Lisp expressions are evaluated for their side-effects.

>> I tried (progn str (shell-quote-argument str))
>> instead but the same error again.
>
> Of course: any use `str` within an actual expression (as opposed to
> using it as a skeleton element) will work reliably only if that occurs
> after a use of `str` as a skeleton element.
>
>
>         Stefan

Thanks for your patience and help.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]