* Re: wrong type error in local variables
@ 2020-07-03 8:33 Anders Munch
2020-07-03 10:36 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-03 14:07 ` Douglas Lewan
0 siblings, 2 replies; 20+ messages in thread
From: Anders Munch @ 2020-07-03 8:33 UTC (permalink / raw)
To: help-gnu-emacs
Emanuel Berg:
>> Okay, but what exactly is the problem with it, from Lisp?
Douglas Lewan:
> The problem is that it changes the buffer.
Which is sometimes what you want.
I grepped my personal elisp for find-file, and found three uses, neither of which
could be replaced by find-file-noselect.
regards,
Anders
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: wrong type error in local variables
2020-07-03 8:33 wrong type error in local variables Anders Munch
@ 2020-07-03 10:36 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-03 14:07 ` Douglas Lewan
1 sibling, 0 replies; 20+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-07-03 10:36 UTC (permalink / raw)
To: help-gnu-emacs
Anders Munch wrote:
>>> Okay, but what exactly is the problem with it,
>>>
>> from Lisp?
>> The problem is that it changes the buffer.
>
> Which is sometimes what you want. I grepped my
> personal elisp for find-file, and found three uses,
> neither of which could be replaced by
> find-file-noselect.
Okay? Do tell?
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: wrong type error in local variables
2020-07-03 8:33 wrong type error in local variables Anders Munch
2020-07-03 10:36 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2020-07-03 14:07 ` Douglas Lewan
1 sibling, 0 replies; 20+ messages in thread
From: Douglas Lewan @ 2020-07-03 14:07 UTC (permalink / raw)
To: Anders Munch, help-gnu-emacs
On 7/3/20 4:33 AM, Anders Munch wrote:
> Douglas Lewan:
>> The problem is that it changes the buffer.
> Which is sometimes what you want.
> I grepped my personal elisp for find-file, and found three uses, neither of which
> could be replaced by find-file-noselect.
>
> regards,
> Anders
I agree. /Sometimes/ it's what you want. I know I've written things that
use dired-find-file, but that's usually the last thing I call. The
underlying application doesn't depend on switching to another buffer;
it's just that the result switches the buffer at the end just for the
user. /Usually/ an application doesn't want to do that. After all,
switching buffers more than once might undo a previous switch.
--
,Doug
d.lewan2000@gmail.com
(908) 720 7908
If this is what winning looks like, I'd hate to see what losing is.
^ permalink raw reply [flat|nested] 20+ messages in thread
* wrong type error in local variables
@ 2020-07-02 14:46 Douglas Lewan
2020-07-02 15:06 ` Joost Kremers
2020-07-02 15:56 ` Stefan Monnier
0 siblings, 2 replies; 20+ messages in thread
From: Douglas Lewan @ 2020-07-02 14:46 UTC (permalink / raw)
To: help-gnu-emacs
I have a TeX file with the following local variables:
Local Variables:
eval: (ab-new-buffer (prog1 (find-file "chapter16.tex") (message "After find file.")))
End:
The (find-file) succeeds. (There's a buffer with that file and I see the
message.) However, overall I get this error:
File local-variables error: (wrong-type-argument stringp nil)
I assume the call to (ab-new-buffer) gets the error, but as far as I can
tell that call never happens. (ab-new-buffer) has the following definition:
(defun ab-new-buffer (buffer-or-name)
(error "Now in (ab-new-buffer)."))
I never see that error.
What am I missing?
FYI The data above are obviously reduced to a minimal case. With the
correct definition of (ab-new-buffer) a full battery of tests passes.
--
,Doug
d.lewan2000@gmail.com
(908) 720 7908
If this is what winning looks like, I'd hate to see what losing is.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: wrong type error in local variables
2020-07-02 14:46 Douglas Lewan
@ 2020-07-02 15:06 ` Joost Kremers
2020-07-02 15:59 ` Douglas Lewan
2020-07-02 15:56 ` Stefan Monnier
1 sibling, 1 reply; 20+ messages in thread
From: Joost Kremers @ 2020-07-02 15:06 UTC (permalink / raw)
To: help-gnu-emacs
On Thu, Jul 02 2020, Douglas Lewan wrote:
> I have a TeX file with the following local variables:
>
> Local Variables:
> eval: (ab-new-buffer (prog1 (find-file "chapter16.tex")
> (message "After find file.")))
> End:
>
> The (find-file) succeeds. (There's a buffer with that file and I
> see the
> message.) However, overall I get this error:
>
> File local-variables error: (wrong-type-argument stringp
> nil)
>
> I assume the call to (ab-new-buffer) gets the error, but as far
> as I can
> tell that call never happens. (ab-new-buffer) has the following
> definition:
>
> (defun ab-new-buffer (buffer-or-name)
> (error "Now in (ab-new-buffer)."))
>
> I never see that error.
> What am I missing?
>
> FYI The data above are obviously reduced to a minimal case. With
> the
> correct definition of (ab-new-buffer) a full battery of tests
> passes.
Seems to work fine for me. Are you sure you have nothing else in
your local variables block? And what about the local variables
block of the file you're finding in your local variables block
(i.e., "chapter16.tex")?
Try setting `debug-on-error` (do `M-x toggle-debug-on-error`) and
then open the file. You should then get a backtrace that may
provide more information. If you don't know what to make of it,
post it here.
HTH
--
Joost Kremers
Life has its moments
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: wrong type error in local variables
2020-07-02 15:06 ` Joost Kremers
@ 2020-07-02 15:59 ` Douglas Lewan
0 siblings, 0 replies; 20+ messages in thread
From: Douglas Lewan @ 2020-07-02 15:59 UTC (permalink / raw)
To: Joost Kremers, help-gnu-emacs
On 7/2/20 11:06 AM, Joost Kremers wrote:
>
> On Thu, Jul 02 2020, Douglas Lewan wrote:
>> I have a TeX file with the following local variables:
>>
>> Local Variables:
>> eval: (ab-new-buffer (prog1 (find-file "chapter16.tex")
>> (message "After find file.")))
>> End:
>>
>> The (find-file) succeeds. (There's a buffer with that file and I see
>> the message.) However, overall I get this error:
>>
>> File local-variables error: (wrong-type-argument stringp nil)
>>
>> I assume the call to (ab-new-buffer) gets the error, but as far as I
>> can tell that call never happens. (ab-new-buffer) has the following
>> definition:
>>
>> (defun ab-new-buffer (buffer-or-name)
>> (error "Now in (ab-new-buffer)."))
>>
>> I never see that error.
>> What am I missing?
>>
>> FYI The data above are obviously reduced to a minimal case. With the
>> correct definition of (ab-new-buffer) a full battery of tests passes.
>
> Seems to work fine for me. Are you sure you have nothing else in your
> local variables block? And what about the local variables block of the
> file you're finding in your local variables block (i.e.,
> "chapter16.tex")?
I do have other things in the local variables, but that suggestion
prompted me to try this in emacs -Q where I do see the above error.
I'll try again in a clean emacs.
Now I have to wonder just how dirty I've made emacs....
Thanks for the prompt.
--
,Doug
d.lewan2000@gmail.com
(908) 720 7908
If this is what winning looks like, I'd hate to see what losing is.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: wrong type error in local variables
2020-07-02 14:46 Douglas Lewan
2020-07-02 15:06 ` Joost Kremers
@ 2020-07-02 15:56 ` Stefan Monnier
2020-07-02 16:36 ` Emanuel Berg via Users list for the GNU Emacs text editor
` (2 more replies)
1 sibling, 3 replies; 20+ messages in thread
From: Stefan Monnier @ 2020-07-02 15:56 UTC (permalink / raw)
To: help-gnu-emacs
> Local Variables:
> eval: (ab-new-buffer (prog1 (find-file "chapter16.tex") (message "After find file.")))
> End:
Joost Kremers gave a good answer. I'll just add some "unrelated" comments:
- `find-file` should not be called from Elisp.
Use `find-file-noselect` instead.
- It's OK to temporarily change to another buffer, but your "eval"
should eventually return to the original buffer. Otherwise, do expect
weird behaviors. IOW wrap a `save/with-current-buffer` around your code.
Stefan
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: wrong type error in local variables
2020-07-02 15:56 ` Stefan Monnier
@ 2020-07-02 16:36 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-02 17:09 ` Douglas Lewan
2020-07-02 17:42 ` Stefan Monnier
2020-07-02 17:04 ` Douglas Lewan
2020-07-02 17:15 ` Douglas Lewan
2 siblings, 2 replies; 20+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-07-02 16:36 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier wrote:
> `find-file` should not be called from Elisp.
> Use `find-file-noselect` instead.
Oups, if so I have 15 changes to make.
Why doesn't the byte compiler say this?
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: wrong type error in local variables
2020-07-02 16:36 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2020-07-02 17:09 ` Douglas Lewan
2020-07-02 17:45 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-02 17:42 ` Stefan Monnier
1 sibling, 1 reply; 20+ messages in thread
From: Douglas Lewan @ 2020-07-02 17:09 UTC (permalink / raw)
To: help-gnu-emacs
On 7/2/20 12:36 PM, Emanuel Berg via Users list for the GNU Emacs text
editor wrote:
> Stefan Monnier wrote:
>
>> `find-file` should not be called from Elisp.
>> Use `find-file-noselect` instead.
> Oups, if so I have 15 changes to make.
>
> Why doesn't the byte compiler say this?
Or even the docstring? Lots of docstrings mention such things.
--
,Doug
d.lewan2000@gmail.com
(908) 720 7908
If this is what winning looks like, I'd hate to see what losing is.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: wrong type error in local variables
2020-07-02 16:36 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-02 17:09 ` Douglas Lewan
@ 2020-07-02 17:42 ` Stefan Monnier
2020-07-03 1:19 ` Emanuel Berg via Users list for the GNU Emacs text editor
1 sibling, 1 reply; 20+ messages in thread
From: Stefan Monnier @ 2020-07-02 17:42 UTC (permalink / raw)
To: help-gnu-emacs
>> `find-file` should not be called from Elisp.
>> Use `find-file-noselect` instead.
> Oups, if so I have 15 changes to make.
> Why doesn't the byte compiler say this?
Because noone has added the annotation for it yet (tho there are
various comments in the code that say so).
FWIW, I just tried adding it (see patch below), and I see that we have
many cases in Emacs's own Lisp code where we call `find-file`
from Elisp. I suspect that many of them would benefit from being
changed, but the need to go and update all those cases might be a
reason why it hasn't been done yet :-(
Stefan
diff --git a/lisp/files.el b/lisp/files.el
index 742fd78df1d..a29d02bf591 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1688,6 +1688,7 @@ find-file
To visit a file without any kind of conversion and without
automatically choosing a major mode, use \\[find-file-literally]."
+ (declare (interactive-only find-file-noselect))
(interactive
(find-file-read-args "Find file: "
(confirm-nonexistent-file-or-buffer)))
@@ -1761,15 +1762,16 @@ find-file-other-frame
(switch-to-buffer-other-frame value))))
(defun find-file-existing (filename)
- "Edit the existing file FILENAME.
+ "Edit the existing file FILENAME.
Like \\[find-file], but allow only a file that exists, and do not allow
file names with wildcards."
- (interactive (nbutlast (find-file-read-args "Find existing file: " t)))
- (if (and (not (called-interactively-p 'interactive))
- (not (file-exists-p filename)))
- (error "%s does not exist" filename)
- (find-file filename)
- (current-buffer)))
+ (interactive (nbutlast (find-file-read-args "Find existing file: " t)))
+ (if (not (or (called-interactively-p 'interactive)
+ (file-exists-p filename)))
+ (error "%s does not exist" filename)
+ (with-suppressed-warnings ((interactive-only find-file))
+ (find-file filename))
+ (current-buffer)))
(defun find-file--read-only (fun filename wildcards)
(unless (or (and wildcards find-file-wildcards
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: wrong type error in local variables
2020-07-02 17:42 ` Stefan Monnier
@ 2020-07-03 1:19 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-03 1:40 ` Douglas Lewan
0 siblings, 1 reply; 20+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-07-03 1:19 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier wrote:
>>> `find-file` should not be called from Elisp.
>>> Use `find-file-noselect` instead.
>>
>> Oups, if so I have 15 changes to make. Why doesn't
>> the byte compiler say this?
>
> Because noone has added the annotation for it yet
> (tho there are various comments in the code that
> say so).
Okay, but what exactly is the problem with it,
from Lisp?
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: wrong type error in local variables
2020-07-03 1:19 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2020-07-03 1:40 ` Douglas Lewan
2020-07-03 2:00 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-03 3:45 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 2 replies; 20+ messages in thread
From: Douglas Lewan @ 2020-07-03 1:40 UTC (permalink / raw)
To: Emanuel Berg, help-gnu-emacs
On 7/2/20 9:19 PM, Emanuel Berg via Users list for the GNU Emacs text
editor wrote:
> Stefan Monnier wrote:
>
>>>> `find-file` should not be called from Elisp.
>>>> Use `find-file-noselect` instead.
>>> Oups, if so I have 15 changes to make. Why doesn't
>>> the byte compiler say this?
>> Because noone has added the annotation for it yet
>> (tho there are various comments in the code that
>> say so).
> Okay, but what exactly is the problem with it,
> from Lisp?
>
The problem is that it changes the buffer.
If a (find-file) fails and you were depending on the change of the
current buffer all kinds of other things might go wrong.
If you use (find-file-noselect), then the current buffer doesn't change
and any attempt to use that buffer would fail. In particular, you should
be verifying that the (find-file-noselect) succeeded.
--
,Doug
d.lewan2000@gmail.com
(908) 720 7908
If this is what winning looks like, I'd hate to see what losing is.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: wrong type error in local variables
2020-07-03 1:40 ` Douglas Lewan
@ 2020-07-03 2:00 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-03 2:24 ` Douglas Lewan
2020-07-03 3:45 ` Emanuel Berg via Users list for the GNU Emacs text editor
1 sibling, 1 reply; 20+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-07-03 2:00 UTC (permalink / raw)
To: help-gnu-emacs
Douglas Lewan wrote:
>> Okay, but what exactly is the problem with it,
>> from Lisp?
>
> The problem is that it changes the buffer.
>
> If a (find-file) fails and you were depending on
> the change of the current buffer all kinds of other
> things might go wrong.
>
> If you use (find-file-noselect), then the current
> buffer doesn't change and any attempt to use that
> buffer would fail. In particular, you should be
> verifying that the (find-file-noselect) succeeded.
Gotcha, but then why not just have a single such
function that does the checking itself and aborts
further execution immediately after the initial,
failed attempt to find the file? Then 1 (onee)
function would be used, and with no need to
explicitely check if it succeeded?
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: wrong type error in local variables
2020-07-03 2:00 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2020-07-03 2:24 ` Douglas Lewan
0 siblings, 0 replies; 20+ messages in thread
From: Douglas Lewan @ 2020-07-03 2:24 UTC (permalink / raw)
To: help-gnu-emacs
On 7/2/20 10:00 PM, Emanuel Berg via Users list for the GNU Emacs text
editor wrote:
> Douglas Lewan wrote:
>
>>> Okay, but what exactly is the problem with it,
>>> from Lisp?
>> The problem is that it changes the buffer.
>>
>> If a (find-file) fails and you were depending on
>> the change of the current buffer all kinds of other
>> things might go wrong.
>>
>> If you use (find-file-noselect), then the current
>> buffer doesn't change and any attempt to use that
>> buffer would fail. In particular, you should be
>> verifying that the (find-file-noselect) succeeded.
> Gotcha, but then why not just have a single such
> function that does the checking itself and aborts
> further execution immediately after the initial,
> failed attempt to find the file? Then 1 (onee)
> function would be used, and with no need to
> explicitely check if it succeeded?
I understand. Such a solution has already been proposed here. I'm just
responding to the world we currently live in. And, yes, encapsulation of
such issues is a reasonable thing.
--
,Doug
d.lewan2000@gmail.com
(908) 720 7908
If this is what winning looks like, I'd hate to see what losing is.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: wrong type error in local variables
2020-07-03 1:40 ` Douglas Lewan
2020-07-03 2:00 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2020-07-03 3:45 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-03 5:13 ` Douglas Lewan
1 sibling, 1 reply; 20+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-07-03 3:45 UTC (permalink / raw)
To: help-gnu-emacs
Douglas Lewan wrote:
> you should be verifying that the
> (find-file-noselect) succeeded.
BTW, how do you verify that?
(when (find-file-noselect "~/.emacs") t) ; t
but also
(when (find-file-noselect "~/there-is-no-file") t) ; t
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: wrong type error in local variables
2020-07-02 15:56 ` Stefan Monnier
2020-07-02 16:36 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2020-07-02 17:04 ` Douglas Lewan
2020-07-02 17:15 ` Douglas Lewan
2 siblings, 0 replies; 20+ messages in thread
From: Douglas Lewan @ 2020-07-02 17:04 UTC (permalink / raw)
To: Stefan Monnier, help-gnu-emacs
On 7/2/20 11:56 AM, Stefan Monnier wrote:
> Joost Kremers gave a good answer. I'll just add some "unrelated" comments:
>
> - `find-file` should not be called from Elisp.
> Use `find-file-noselect` instead.
>
> - It's OK to temporarily change to another buffer, but your "eval"
> should eventually return to the original buffer. Otherwise, do expect
> weird behaviors. IOW wrap a `save/with-current-buffer` around your code.
>
>
> Stefan
Done. Thanks.
--
,Doug
d.lewan2000@gmail.com
(908) 720 7908
If this is what winning looks like, I'd hate to see what losing is.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: wrong type error in local variables
2020-07-02 15:56 ` Stefan Monnier
2020-07-02 16:36 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-02 17:04 ` Douglas Lewan
@ 2020-07-02 17:15 ` Douglas Lewan
2 siblings, 0 replies; 20+ messages in thread
From: Douglas Lewan @ 2020-07-02 17:15 UTC (permalink / raw)
To: Stefan Monnier, help-gnu-emacs
On 7/2/20 11:56 AM, Stefan Monnier wrote:
> - It's OK to temporarily change to another buffer, but your "eval"
> should eventually return to the original buffer. Otherwise, do expect
> weird behaviors. IOW wrap a `save/with-current-buffer` around your code.
That was it. Changing the buffer messed up a dependency on the book.tex
buffer.
Thanks.
--
,Doug
d.lewan2000@gmail.com
(908) 720 7908
If this is what winning looks like, I'd hate to see what losing is.
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2020-07-03 14:07 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-03 8:33 wrong type error in local variables Anders Munch
2020-07-03 10:36 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-03 14:07 ` Douglas Lewan
-- strict thread matches above, loose matches on Subject: below --
2020-07-02 14:46 Douglas Lewan
2020-07-02 15:06 ` Joost Kremers
2020-07-02 15:59 ` Douglas Lewan
2020-07-02 15:56 ` Stefan Monnier
2020-07-02 16:36 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-02 17:09 ` Douglas Lewan
2020-07-02 17:45 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-02 17:42 ` Stefan Monnier
2020-07-03 1:19 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-03 1:40 ` Douglas Lewan
2020-07-03 2:00 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-03 2:24 ` Douglas Lewan
2020-07-03 3:45 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-03 5:13 ` Douglas Lewan
2020-07-03 6:05 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-02 17:04 ` Douglas Lewan
2020-07-02 17:15 ` Douglas Lewan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).