unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Go to line
@ 2007-04-23 14:55 PAolo
  2007-04-23 15:08 ` james
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: PAolo @ 2007-04-23 14:55 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

is there some faster way to go to a certain line, rather than
M-x goto-line ?
Can I specify a line number when I open a file with C-x C-f?

THnx
PAolo

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Go to line
  2007-04-23 14:55 Go to line PAolo
@ 2007-04-23 15:08 ` james
  2007-04-23 15:29   ` PAolo
                     ` (2 more replies)
  2007-04-23 15:13 ` Robert D. Crawford
                   ` (2 subsequent siblings)
  3 siblings, 3 replies; 9+ messages in thread
From: james @ 2007-04-23 15:08 UTC (permalink / raw)
  To: help-gnu-emacs

On Apr 23, 9:55 am, PAolo <paolopanta...@gmail.com> wrote:
> Hi,
>
> is there some faster way to go to a certain line, rather than
> M-x goto-line ?
> Can I specify a line number when I open a file with C-x C-f?
>
> THnx
> PAolo

In my emacs, it is bound to M-g M-g (as well as M-g g).  If it isn't
in yours, check what it is bound to with C-h k, and if it's clear (or
you're willing to override it), add this to your .emacs:

(global-set-key (kbd "M-g M-g") 'goto-line)

Or perhaps use this binding, which is not to be used by any major
modes, by convention:
(global-set-key (kbd "C-c g") 'goto-line)

FWIW, you can find out if a function is bound to, if anything, by
bringing up the command's documentation.  C-h a  for apropos-command,
then "goto-line".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Go to line
  2007-04-23 14:55 Go to line PAolo
  2007-04-23 15:08 ` james
@ 2007-04-23 15:13 ` Robert D. Crawford
  2007-04-23 18:36 ` Matthew Flaschen
  2007-04-23 20:00 ` Dieter Wilhelm
  3 siblings, 0 replies; 9+ messages in thread
From: Robert D. Crawford @ 2007-04-23 15:13 UTC (permalink / raw)
  To: help-gnu-emacs

PAolo <paolopantaleo@gmail.com> writes:

> is there some faster way to go to a certain line, rather than
> M-x goto-line ?

Retrieved via C-h a goto-line:

goto-line		       <menu-bar> <edit> <goto> <go-to-line> ,  meta g meta g ,  meta g g 
  Command: Goto line ARG, counting from line 1 at beginning of buffer.

I am not sure if there was a change between versions, but I am using the
cvs version 

GNU Emacs 22.0.98.1 (i686-pc-linux-gnu) of 2007-04-17 on t40

> Can I specify a line number when I open a file with C-x C-f?

Retrieved via C-h k C-x C-f

 control x control f  runs the command find-file
  which is an interactive compiled Lisp function in `files.el'.
It is bound to  <open> ,  control x control f ,  <menu-bar> <file> <new-file> .
(find-file FILENAME &optional WILDCARDS)

Edit file FILENAME.
Switch to a buffer visiting file FILENAME,
creating one if none already exists.
Interactively, the default if you just type RET is the current directory,
but the visited file name is available through the minibuffer history:
type M-n to pull it into the minibuffer.

Interactively, or if WILDCARDS is non-nil in a call from Lisp,
expand wildcards (if any) and visit multiple files.  You can
suppress wildcard expansion by setting `find-file-wildcards' to nil.

To visit a file without any kind of conversion and without
automatically choosing a major mode, use M-x find-file-literally.

rdc
-- 
Robert D. Crawford                                      rdc1x@comcast.net

Some men are so interested in their wives' continued happiness that they
hire detectives to find out the reason for it.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Go to line
  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
  2 siblings, 0 replies; 9+ messages in thread
From: PAolo @ 2007-04-23 15:29 UTC (permalink / raw)
  To: help-gnu-emacs

On 23 Apr, 17:08, james <james.kings...@gmail.com> wrote:
> On Apr 23, 9:55 am, PAolo <paolopanta...@gmail.com> wrote:
>
> > Hi,
>
> > is there some faster way to go to a certain line, rather than
> > M-x goto-line ?
> > Can I specify a line number when I open a file with C-x C-f?
>
> > THnx
> > PAolo
>
> In my emacs, it is bound to M-g M-g (as well as M-g g).  If it isn't
> in yours, check what it is bound to with C-h k, and if it's clear (or
> you're willing to override it), add this to your .emacs:
>
> (global-set-key (kbd "M-g M-g") 'goto-line)
>
> Or perhaps use this binding, which is not to be used by any major
> modes, by convention:
> (global-set-key (kbd "C-c g") 'goto-line)
>
> FWIW, you can find out if a function is bound to, if anything, by
> bringing up the command's documentation.  C-h a  for apropos-command,
> then "goto-line".

Thanks, I'm using emacs 21 packed by Debian, and the M-g M-g key bind
is not set. I edited the .emacs file.

Greetings
PAolo

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Go to line
  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
  2 siblings, 0 replies; 9+ messages in thread
From: Joost Kremers @ 2007-04-23 15:41 UTC (permalink / raw)
  To: help-gnu-emacs

james wrote:
> FWIW, you can find out if a function is bound to, if anything, by
> bringing up the command's documentation.  C-h a  for apropos-command,
> then "goto-line".

or, IMHO quicker: C-h w


-- 
Joost Kremers                                      joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Go to line
  2007-04-23 14:55 Go to line PAolo
  2007-04-23 15:08 ` james
  2007-04-23 15:13 ` Robert D. Crawford
@ 2007-04-23 18:36 ` Matthew Flaschen
  2007-04-23 20:00 ` Dieter Wilhelm
  3 siblings, 0 replies; 9+ messages in thread
From: Matthew Flaschen @ 2007-04-23 18:36 UTC (permalink / raw)
  To: emacs

PAolo wrote:
> Hi,
> 
> is there some faster way to go to a certain line, rather than
> M-x goto-line ?

I bound it to C-x g, FWIW.

Matt Flaschen

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Go to line
  2007-04-23 14:55 Go to line PAolo
                   ` (2 preceding siblings ...)
  2007-04-23 18:36 ` Matthew Flaschen
@ 2007-04-23 20:00 ` Dieter Wilhelm
  2007-04-24 10:01   ` Stephen Berman
  3 siblings, 1 reply; 9+ messages in thread
From: Dieter Wilhelm @ 2007-04-23 20:00 UTC (permalink / raw)
  To: PAolo; +Cc: help-gnu-emacs

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.

-- 
    Best wishes

    H. Dieter Wilhelm
    Darmstadt, Germany

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Go to line
  2007-04-23 20:00 ` Dieter Wilhelm
@ 2007-04-24 10:01   ` Stephen Berman
  0 siblings, 0 replies; 9+ messages in thread
From: Stephen Berman @ 2007-04-24 10:01 UTC (permalink / raw)
  To: help-gnu-emacs

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Go to line
  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
  2 siblings, 0 replies; 9+ messages in thread
From: Tim X @ 2007-04-24 10:45 UTC (permalink / raw)
  To: help-gnu-emacs

james <james.kingston@gmail.com> writes:

> On Apr 23, 9:55 am, PAolo <paolopanta...@gmail.com> wrote:
>> Hi,
>>
>> is there some faster way to go to a certain line, rather than
>> M-x goto-line ?
>> Can I specify a line number when I open a file with C-x C-f?
>>
>> THnx
>> PAolo
>
> In my emacs, it is bound to M-g M-g (as well as M-g g).  If it isn't
> in yours, check what it is bound to with C-h k, and if it's clear (or
> you're willing to override it), add this to your .emacs:
>
> (global-set-key (kbd "M-g M-g") 'goto-line)
>
> Or perhaps use this binding, which is not to be used by any major
> modes, by convention:
> (global-set-key (kbd "C-c g") 'goto-line)
>
> FWIW, you can find out if a function is bound to, if anything, by
> bringing up the command's documentation.  C-h a  for apropos-command,
> then "goto-line".
>
>

FYI, binding of goto-line to M-g M-g etc was introduced in CVS emacs (Emacs 22).
Priot to that, the function was not bound to any key sequence by default. Prior
to using emacs 22, I use to bind it to F6. 

I don't believe there is any way to specify a line to go to with C-x C-f.
However, it wouldn't be that hard to write your own interactive find file
function that did this for you and prompted for the line number. You could even
use defadvice to modify how find-file works. have a go, post your attempts and
then we will provide assistance if needed.

Tim

-- 
tcross (at) rapttech dot com dot au

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-04-24 10:45 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).