From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.help Subject: Re: Go to line Date: Tue, 24 Apr 2007 12:01:40 +0200 Message-ID: <877is2m6pn.fsf@escher.local.home> References: <1177340103.887135.165610@p77g2000hsh.googlegroups.com> <87vefmyi7q.fsf@debby.local.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1177408949 10104 80.91.229.12 (24 Apr 2007 10:02:29 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 24 Apr 2007 10:02:29 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Apr 24 12:02:27 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HgHqr-0007PF-AW for geh-help-gnu-emacs@m.gmane.org; Tue, 24 Apr 2007 12:02:25 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HgHwL-0008Ue-IL for geh-help-gnu-emacs@m.gmane.org; Tue, 24 Apr 2007 06:08:05 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HgHw5-0008TK-HG for help-gnu-emacs@gnu.org; Tue, 24 Apr 2007 06:07:49 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HgHw4-0008RE-5F for help-gnu-emacs@gnu.org; Tue, 24 Apr 2007 06:07:48 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HgHw3-0008Qz-Ta for help-gnu-emacs@gnu.org; Tue, 24 Apr 2007 06:07:47 -0400 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1HgHqY-0003aP-Fg for help-gnu-emacs@gnu.org; Tue, 24 Apr 2007 06:02:06 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1HgHqK-00032E-UW for help-gnu-emacs@gnu.org; Tue, 24 Apr 2007 12:01:53 +0200 Original-Received: from i577bc88a.versanet.de ([87.123.200.138]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 24 Apr 2007 12:01:52 +0200 Original-Received: from Stephen.Berman by i577bc88a.versanet.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 24 Apr 2007 12:01:52 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 65 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: i577bc88a.versanet.de User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.98 (gnu/linux) X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:43055 Archived-At: On Mon, 23 Apr 2007 22:00:09 +0200 Dieter Wilhelm wrote: > PAolo 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