Skip to content

Commit

Permalink
Added helper to open file with emacsclient using filename:line path
Browse files Browse the repository at this point in the history
Most of console-based utilities prints filename in format
"filename:linenumber". So you may wish to open filename in that format.
This little 'advice' can do that. Just call

emacsclient filename:linenumber

and cursor will be positioned on requested line
  • Loading branch information
lexa committed Nov 30, 2014
1 parent cba761c commit 8c55c6f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ alias vi='emacsclient -t'
The last two aliases are helpful if you're used to editing files from
the command line using `vi(m)`.

Also you can open a file with cursor on choosen line:

```bash
emacsclient somefile:1234
```

This will open file 'somefile' and set cursor on line 1234.

## Getting to know Prelude

Certainly the best way to understand how Prelude enhances the default
Expand Down
19 changes: 19 additions & 0 deletions core/prelude-editor.el
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,25 @@ indent yanked text (with prefix arg don't indent)."
("%" . apply-operation-to-number-at-point)
("'" . operate-on-number-at-point)))

(defadvice server-visit-files (before parse-numbers-in-lines (files proc &optional nowait) activate)
"Open file with emacsclient with cursors positioned on requested line.
Most of console-based utilities prints filename in format
'filename:linenumber'. So you may wish to open filename in that format.
Just call:
emacsclient filename:linenumber
and file 'filename' will be opened and cursor set on line 'linenumber'"
(ad-set-arg 0
(mapcar (lambda (fn)
(let ((name (car fn)))
(if (string-match "^\\(.*?\\):\\([0-9]+\\)\\(?::\\([0-9]+\\)\\)?$" name)
(cons
(match-string 1 name)
(cons (string-to-number (match-string 2 name))
(string-to-number (or (match-string 3 name) ""))))
fn))) files)))

(provide 'prelude-editor)

;;; prelude-editor.el ends here

0 comments on commit 8c55c6f

Please sign in to comment.