diff --git a/configuration.org b/configuration.org index e0fb05e..53697cc 100644 --- a/configuration.org +++ b/configuration.org @@ -201,6 +201,31 @@ Taken from [[http://ergoemacs.org/emacs/emacs_set_backup_into_a_directory.html][ (insert (funcall func text))))) #+END_SRC +*** Copy and show the current location + +#+begin_src emacs-lisp +(defun mbork/copy-current-location (arg) + "Show the current location and put it into the kill ring. + +Without a prefix, the filename will be relative +to `(vc-root-dir)' if the file is under version control and will +be relative to the file’s directory otherwise. With a single +prefix, the filename will be used with an absolute path. With at +least two prefixes the filename will be relative to the file’s +directory." + (interactive "p") + (let ((root (vc-root-dir))) + (if (not buffer-file-name) + (message "Not visiting a file") + (let* ((file-name (cond ((eq arg 1) (file-relative-name buffer-file-name root)) + ((eq arg 4) buffer-file-name) + (t (file-relative-name buffer-file-name nil)))) + (line-number (line-number-at-pos nil t)) + (location (format "%s:%s" file-name line-number))) + (kill-new location) + (message location))))) +#+end_src + ** Check if we are running under Termux We need to do things differently, if so.