emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] add emacsclient support to open with file:linum syntax


From: Toon Claes
Subject: Re: [PATCH] add emacsclient support to open with file:linum syntax
Date: Tue, 14 Feb 2017 14:57:45 +0100

> On 9 Feb 2017, at 14:22, Stefan Monnier <address@hidden> wrote:
> 
> Put the advice on `find-file-noselect`?
> 
> 
>        Stefan


Thanks a lot Stefan!
This is in fact the working defadvice:

#+begin_src emacs-lisp :tangle yes
  (defadvice find-file-noselect (around find-file-noselect-at-line
                                        (filename &optional nowarn rawfile 
wildcards)
                                        activate)
    "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))
             (buffer-name ad-do-it))
        (when line-number
          (with-current-buffer buffer-name
            (goto-char (point-min))
            (forward-line (1- line-number)))))))
#+end_src


Enjoy!

Toon


reply via email to

[Prev in Thread] Current Thread [Next in Thread]