feat(emacs): make emacs open file to a line like a normal editor

When opening files in emacs from the terminal using the default command `+LINE`
is not really useful an no programs output files and lines in that format. All
programmes output a file like `path/to/file.ext:2` this is line 2 in the file
`path/to/file.ext` if you were to open this with the emacs command it would be
`emacs +2 path/to/file.ext`. With this commit you can use `emacs
path/to/file.ext:2` and it will open the file on line 2 like you would expect.

As a extra I have overridden the tmux open command to add the `--no-wait` to the
editor command so that we can continue to use the terminal window as the file is
open in emacs and we don't need to close the file to use the terminal.
This commit is contained in:
Ade Attwood 2020-11-04 20:15:44 +00:00
parent b68fd82987
commit 9bb1595dec
3 changed files with 18 additions and 0 deletions

View file

@ -547,6 +547,21 @@ dump."
(add-hook 'vterm-mode-hook 'aa/setup-term-mode)
(add-hook 'term-mode-hook 'aa/setup-term-mode)
;; Sort out line numbers
;; https://stackoverflow.com/a/23857738
(defadvice server-visit-files (before parse-numbers-in-lines (files proc &optional nowait) activate)
"looks for filenames like file:line or file:line:position and reparses name in such manner that position in file"
(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))
)
;; Define a kanban style set of stages for todo tasks
(with-eval-after-load 'org
(setq org-todo-keywords

View file

@ -50,6 +50,7 @@ set -g mouse on
set-option -g mouse on
set -g @open-S 'https://www.duckduckgo.com/'
set -g @open-editor-command 'emacs --no-wait'
# Init plugins
run-shell ~/.tmux/plugins/tmux-copycat/copycat.tmux

View file

@ -84,6 +84,8 @@ export GOPATH=$HOME/go
#
source $ZSH/oh-my-zsh.sh
export EDITOR="emacs --no-wait"
#
# Import local alases if the file exists
#