Adopt mbork’s copy-current-location function

This commit is contained in:
Gergely Polonkai 2022-08-18 07:21:31 +02:00
parent f900ffc47d
commit 4e87ff3355
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4
1 changed files with 25 additions and 0 deletions

View File

@ -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 files 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 files
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.