pinwheel: Add Emacs command to copy file path with line number
This commit is contained in:
1 file changed
+26
@@ -410,6 +410,32 @@ Setup prefix for keybindings.
|
|||||||
"t" '(:ignore t :which-key "text")
|
"t" '(:ignore t :which-key "text")
|
||||||
"ts" '(hydra-text-scale/body :which-key "scale text"))
|
"ts" '(hydra-text-scale/body :which-key "scale text"))
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
** Copy file path with line number
|
||||||
|
#+BEGIN_SRC emacs-lisp
|
||||||
|
(defun alex/copy-path-with-line ()
|
||||||
|
"Copy /abs/path:LINE, or /abs/path:START-END when a region is active."
|
||||||
|
(interactive)
|
||||||
|
(unless buffer-file-name (user-error "Buffer is not visiting a file"))
|
||||||
|
(let* ((path (expand-file-name buffer-file-name))
|
||||||
|
(ref (if (use-region-p)
|
||||||
|
(let* ((beg (region-beginning))
|
||||||
|
(end (if (and (> (region-end) beg)
|
||||||
|
(save-excursion (goto-char (region-end)) (bolp)))
|
||||||
|
(1- (region-end))
|
||||||
|
(region-end)))
|
||||||
|
(start-line (line-number-at-pos beg))
|
||||||
|
(end-line (line-number-at-pos end)))
|
||||||
|
(if (= start-line end-line)
|
||||||
|
(format "%s:%d" path start-line)
|
||||||
|
(format "%s:%d-%d" path start-line end-line)))
|
||||||
|
(format "%s:%d" path (line-number-at-pos)))))
|
||||||
|
(kill-new ref)
|
||||||
|
(deactivate-mark)
|
||||||
|
(message "Copied %s" ref)))
|
||||||
|
|
||||||
|
(alex/keybindings
|
||||||
|
"y" '(alex/copy-path-with-line :which-key "copy path:line"))
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
* Browser
|
* Browser
|
||||||
#+BEGIN_SRC emacs-lisp
|
#+BEGIN_SRC emacs-lisp
|
||||||
|
|||||||
Reference in new issue
Block a user