From 9bb1595dec231559b9b1a4221babdb18f209a36e Mon Sep 17 00:00:00 2001 From: Ade Attwood Date: Wed, 4 Nov 2020 20:15:44 +0000 Subject: [PATCH] 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. --- site-modules/core/files/emacs/spacemacs | 15 +++++++++++++++ site-modules/core/files/tmux.conf | 1 + site-modules/core/files/zshrc | 2 ++ 3 files changed, 18 insertions(+) diff --git a/site-modules/core/files/emacs/spacemacs b/site-modules/core/files/emacs/spacemacs index 3f4f86e..b7204fc 100644 --- a/site-modules/core/files/emacs/spacemacs +++ b/site-modules/core/files/emacs/spacemacs @@ -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 diff --git a/site-modules/core/files/tmux.conf b/site-modules/core/files/tmux.conf index a999a62..8113b84 100644 --- a/site-modules/core/files/tmux.conf +++ b/site-modules/core/files/tmux.conf @@ -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 diff --git a/site-modules/core/files/zshrc b/site-modules/core/files/zshrc index ec6353f..58ed442 100644 --- a/site-modules/core/files/zshrc +++ b/site-modules/core/files/zshrc @@ -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 #