* Command line open does not use find-file anymore?
@ 2017-09-18 9:00 Everton J. Carpes
2017-09-18 15:47 ` Óscar Fuentes
2017-09-19 11:38 ` Michael Heerdegen
0 siblings, 2 replies; 6+ messages in thread
From: Everton J. Carpes @ 2017-09-18 9:00 UTC (permalink / raw)
To: help-gnu-emacs
Until emacs 24 I was able to customize file opening using an "advice"
around find-file. It was working for opening from inside emacs and also
from command line.
I use this to deal with common error reports, which are presented in
"filename:lineno" syntax. The suggestion to do this can be found here:
>
https://stackoverflow.com/questions/3139970/open-a-file-at-line-with-filenameline-syntax
After updating to version 25 (actually 25.2.2) and follow the instructions
to update advice which I found here:
>
https://www.gnu.org/software/emacs/manual/html_node/elisp/Porting-old-advice.html
The around is working when find-file is called from inside emacs, but not
when emacs is called from command line.
1. Emacs 25 doesn't use find-file anymore when opening from command line?
2. Which function is called now?
3. Is this the best way to deal with this kind of customization?
4. How can I learn more about what emacs does when opened?
I spect this is the proper mailing list to post this question. If not,
really sorry and I appreciate instructions about where and how to post this.
Thanks for your time.
P.S.: Just for reference, the code I'm using (the same posted on SO), after
update it into the new advice syntax is:
(defun find-file--line-number (orig-fun filename &optional wildcards)
"Turn files like file.cpp:14 into file.cpp and going to the 14-th line."
(save-match-data
(let* ((matched (string-match "^\\(.*\\):\\([0-9]+\\):?$" filename))
(line-number (and matched
(match-string 2 filename)
(string-to-number (match-string 2 filename))))
(filename (if matched (match-string 1 filename) filename)))
(apply orig-fun (list filename wildcards))
(when line-number
;; goto-line is for interactive use
(goto-char (point-min))
(forward-line (1- line-number))))))
(advice-add 'find-file :around #'find-file--line-number)
--
Everton J. Carpes
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Command line open does not use find-file anymore?
2017-09-18 9:00 Command line open does not use find-file anymore? Everton J. Carpes
@ 2017-09-18 15:47 ` Óscar Fuentes
2017-09-18 17:36 ` Everton J. Carpes
2017-09-19 11:38 ` Michael Heerdegen
1 sibling, 1 reply; 6+ messages in thread
From: Óscar Fuentes @ 2017-09-18 15:47 UTC (permalink / raw)
To: help-gnu-emacs
"Everton J. Carpes" <everton.carpes@gmail.com> writes:
> Until emacs 24 I was able to customize file opening using an "advice"
> around find-file. It was working for opening from inside emacs and also
> from command line.
>
> I use this to deal with common error reports, which are presented in
> "filename:lineno" syntax. The suggestion to do this can be found here:
[snip]
By "command line" you refer to starting a new emacs session or invoking
the emacs server with emacsclient?
The documentation says that find-file is used when visiting a file from
the command line (i.e. when you start emacs providing a file name). It
also mentions de syntax +LINE and +LINE:COLUMN for jumping to a specific
positiong. Here is an excerpt from the relevant info node:
C.1 Action Arguments
====================
Here is a table of action arguments:
‘FILE’
‘--file=FILE’
‘--find-file=FILE’
‘--visit=FILE’
Visit FILE using ‘find-file’. *Note Visiting::.
When Emacs starts up, it displays the startup buffer in one window,
and the buffer visiting FILE in another window (*note Windows::).
If you supply more than one file argument, the displayed file is
the last one specified on the command line; the other files are
visited but their buffers are not shown.
If the startup buffer is disabled (*note Entering Emacs::), then
FILE is visited in a single window if one file argument was
supplied; with two file arguments, Emacs displays the files in two
different windows; with more than two file argument, Emacs displays
the last file specified in one window, plus a Buffer Menu in a
different window (*note Several Buffers::). To inhibit using the
Buffer Menu for this, change the variable
‘inhibit-startup-buffer-menu’ to ‘t’.
‘+LINENUM FILE’
Visit FILE using ‘find-file’, then go to line number LINENUM in it.
‘+LINENUM:COLUMNNUM FILE’
Visit FILE using ‘find-file’, then go to line number LINENUM and
put point at column number COLUMNNUM.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Command line open does not use find-file anymore?
2017-09-18 15:47 ` Óscar Fuentes
@ 2017-09-18 17:36 ` Everton J. Carpes
0 siblings, 0 replies; 6+ messages in thread
From: Everton J. Carpes @ 2017-09-18 17:36 UTC (permalink / raw)
To: Óscar Fuentes; +Cc: help-gnu-emacs
By "command line" I means starting a new emacs session.
I know the +LINE syntax, but it is not useful when you are dealing with
error reports from a lot of tools which by default will present it like
FILENAME:LINE.
The solution putting the "advice" around find-file works when calling
find-file inside emacs and was working until version 25 also from command
line, but it is not working from command line anymore after updating to 25.
On Mon, Sep 18, 2017 at 12:47 PM, Óscar Fuentes <ofv@wanadoo.es> wrote:
> "Everton J. Carpes" <everton.carpes@gmail.com> writes:
>
> > Until emacs 24 I was able to customize file opening using an "advice"
> > around find-file. It was working for opening from inside emacs and also
> > from command line.
> >
> > I use this to deal with common error reports, which are presented in
> > "filename:lineno" syntax. The suggestion to do this can be found here:
>
> [snip]
>
> By "command line" you refer to starting a new emacs session or invoking
> the emacs server with emacsclient?
>
> The documentation says that find-file is used when visiting a file from
> the command line (i.e. when you start emacs providing a file name). It
> also mentions de syntax +LINE and +LINE:COLUMN for jumping to a specific
> positiong. Here is an excerpt from the relevant info node:
>
>
> C.1 Action Arguments
> ====================
>
> Here is a table of action arguments:
>
> ‘FILE’
> ‘--file=FILE’
> ‘--find-file=FILE’
> ‘--visit=FILE’
> Visit FILE using ‘find-file’. *Note Visiting::.
>
> When Emacs starts up, it displays the startup buffer in one window,
> and the buffer visiting FILE in another window (*note Windows::).
> If you supply more than one file argument, the displayed file is
> the last one specified on the command line; the other files are
> visited but their buffers are not shown.
>
> If the startup buffer is disabled (*note Entering Emacs::), then
> FILE is visited in a single window if one file argument was
> supplied; with two file arguments, Emacs displays the files in two
> different windows; with more than two file argument, Emacs displays
> the last file specified in one window, plus a Buffer Menu in a
> different window (*note Several Buffers::). To inhibit using the
> Buffer Menu for this, change the variable
> ‘inhibit-startup-buffer-menu’ to ‘t’.
>
> ‘+LINENUM FILE’
> Visit FILE using ‘find-file’, then go to line number LINENUM in it.
>
> ‘+LINENUM:COLUMNNUM FILE’
> Visit FILE using ‘find-file’, then go to line number LINENUM and
> put point at column number COLUMNNUM.
>
>
>
--
Everton J. Carpes
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Command line open does not use find-file anymore?
2017-09-18 9:00 Command line open does not use find-file anymore? Everton J. Carpes
2017-09-18 15:47 ` Óscar Fuentes
@ 2017-09-19 11:38 ` Michael Heerdegen
2017-09-19 16:50 ` Eli Zaretskii
2017-09-20 1:16 ` Everton J. Carpes
1 sibling, 2 replies; 6+ messages in thread
From: Michael Heerdegen @ 2017-09-19 11:38 UTC (permalink / raw)
To: Everton J. Carpes; +Cc: help-gnu-emacs
"Everton J. Carpes" <everton.carpes@gmail.com> writes:
> 1. Emacs 25 doesn't use find-file anymore when opening from command line?
> 2. Which function is called now?
> 4. How can I learn more about what emacs does when opened?
Seems you are right - the code switched to `find-file-noselect' a while
ago (`find-file' is just a thin wrapper around `find-file-noselect' that
directly selects the file's buffer). You can find that argument
handling code in startup.el, `command-line-1' in particular.
Michael.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Command line open does not use find-file anymore?
2017-09-19 11:38 ` Michael Heerdegen
@ 2017-09-19 16:50 ` Eli Zaretskii
2017-09-20 1:16 ` Everton J. Carpes
1 sibling, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2017-09-19 16:50 UTC (permalink / raw)
To: help-gnu-emacs
> From: Michael Heerdegen <michael_heerdegen@web.de>
> Date: Tue, 19 Sep 2017 13:38:40 +0200
> Cc: help-gnu-emacs@gnu.org
>
> "Everton J. Carpes" <everton.carpes@gmail.com> writes:
>
> > 1. Emacs 25 doesn't use find-file anymore when opening from command line?
> > 2. Which function is called now?
> > 4. How can I learn more about what emacs does when opened?
>
> Seems you are right - the code switched to `find-file-noselect' a while
> ago
Thanks, I've fixed the docs not to mislead its readers.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Command line open does not use find-file anymore?
2017-09-19 11:38 ` Michael Heerdegen
2017-09-19 16:50 ` Eli Zaretskii
@ 2017-09-20 1:16 ` Everton J. Carpes
1 sibling, 0 replies; 6+ messages in thread
From: Everton J. Carpes @ 2017-09-20 1:16 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
Thank you Michael for your reply, it was very instructive, now I can
understand better the whole startup process.
It seems that the change is not only the find-file, but the whole code of
command line parsing, so the approach using the "advice" will not work
anymore (at least, not around find-file similar functions, but I will try
around command-line-1 itself).
On Tue, Sep 19, 2017 at 8:38 AM, Michael Heerdegen <michael_heerdegen@web.de
> wrote:
> "Everton J. Carpes" <everton.carpes@gmail.com> writes:
>
> > 1. Emacs 25 doesn't use find-file anymore when opening from command
> line?
> > 2. Which function is called now?
> > 4. How can I learn more about what emacs does when opened?
>
> Seems you are right - the code switched to `find-file-noselect' a while
> ago (`find-file' is just a thin wrapper around `find-file-noselect' that
> directly selects the file's buffer). You can find that argument
> handling code in startup.el, `command-line-1' in particular.
>
>
> Michael.
>
--
Everton J. Carpes
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-09-20 1:16 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-18 9:00 Command line open does not use find-file anymore? Everton J. Carpes
2017-09-18 15:47 ` Óscar Fuentes
2017-09-18 17:36 ` Everton J. Carpes
2017-09-19 11:38 ` Michael Heerdegen
2017-09-19 16:50 ` Eli Zaretskii
2017-09-20 1:16 ` Everton J. Carpes
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).