From: Stephen Berman <Stephen.Berman@gmx.net>
To: help-gnu-emacs@gnu.org
Subject: Re: Go to line
Date: Tue, 24 Apr 2007 12:01:40 +0200 [thread overview]
Message-ID: <877is2m6pn.fsf@escher.local.home> (raw)
In-Reply-To: 87vefmyi7q.fsf@debby.local.net
On Mon, 23 Apr 2007 22:00:09 +0200 Dieter Wilhelm <dieter@duenenhof-wilhelm.de> wrote:
> PAolo <paolopantaleo@gmail.com> writes:
>
>> M-x goto-line ?
>
> emacs 22.1: M-g M-g
>
>> Can I specify a line number when I open a file with C-x C-f?
>
> You could run emacs-server and open a file on the command line at a
> specified line number LINE_NO.
>
> $ emacsclient +LINE_NO FILE_NAME
>
> otherwise you probably have to write your own find-file function.
Here are two possibilities; the first one doesn't expand wildcards,
the second one does:
(defun srb-visit-file-at-line ()
"Visit an interactively selected file at a given line number.
The line number is provided by prefix argument.
Without a prefix argument, just visit the file."
(interactive)
(let ((num current-prefix-arg)
(find-file-wildcards) ; no wildcard expansion
(last (line-number-at-pos (point-max))))
(call-interactively 'find-file)
(and num
(if (< num last)
(goto-line num)
(error "File only has %d lines" last)))))
(defun srb-visit-file-or-files-at-line ()
"Visit interactively selected file(s) at a given line number.
The line number is provided by prefix argument.
Without a prefix argument, just visit the file(s).
A wildcard in the interactively provided file name is expanded."
(interactive)
(let* ((name (car (find-file-read-args "Find file: " nil)))
(num current-prefix-arg)
(value (find-file-noselect name nil nil t))
bufs last
(err ""))
;; adapted from definition of find-file
(if (listp value)
(setq bufs (mapcar 'switch-to-buffer (nreverse value)))
(switch-to-buffer value)
(setq bufs (list value)))
(and num
(dolist (buf bufs err)
(with-current-buffer buf
(setq last (line-number-at-pos (point-max)))
(if (< num last)
(goto-line num)
(setq err
(concat (format "\n%s only has %d lines" (buffer-name buf)
last)
err)))))
(unless (zerop (length err))
(setq err (substring err 1)) ; chop off initial newline
(error err)))))
Steve Berman
prev parent reply other threads:[~2007-04-24 10:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-23 14:55 Go to line PAolo
2007-04-23 15:08 ` james
2007-04-23 15:29 ` PAolo
2007-04-23 15:41 ` Joost Kremers
2007-04-24 10:45 ` Tim X
2007-04-23 15:13 ` Robert D. Crawford
2007-04-23 18:36 ` Matthew Flaschen
2007-04-23 20:00 ` Dieter Wilhelm
2007-04-24 10:01 ` Stephen Berman [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877is2m6pn.fsf@escher.local.home \
--to=stephen.berman@gmx.net \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).