From 4e87ff3355407f8aa12e3fcc0b28d53d1eb8a468 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Thu, 18 Aug 2022 07:21:31 +0200 Subject: [PATCH] =?UTF-8?q?Adopt=20mbork=E2=80=99s=20copy-current-location?= =?UTF-8?q?=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configuration.org | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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.