feat(ai): refactor path tag helpers and add absolute version
This commit is contained in:
@@ -172,30 +172,39 @@
|
|||||||
(gptel-rewrite-region (region-beginning) (region-end)
|
(gptel-rewrite-region (region-beginning) (region-end)
|
||||||
"Fix spelling, grammar, and improve clarity. Keep the same tone and style.")))
|
"Fix spelling, grammar, and improve clarity. Keep the same tone and style.")))
|
||||||
|
|
||||||
|
(defun my--get-region-as-path-tag (path-fn)
|
||||||
|
"Helper to get path tag using PATH-FN to determine the file path."
|
||||||
|
(let* ((filename (funcall path-fn))
|
||||||
|
(start-line (line-number-at-pos (if (use-region-p) (region-beginning) (point))))
|
||||||
|
(tag (if (use-region-p)
|
||||||
|
(let* ((end-pos (1- (region-end)))
|
||||||
|
(end-line (line-number-at-pos (max (region-beginning) end-pos))))
|
||||||
|
(format "@%s:%d-%d" filename start-line end-line))
|
||||||
|
(format "@%s:%d" filename start-line))))
|
||||||
|
tag))
|
||||||
|
|
||||||
(defun my/copy-region-as-path-tag ()
|
(defun my/copy-region-as-path-tag ()
|
||||||
"Copy the current region as a path tag: @path/to/file.ext:start-end"
|
"Copy the current region as a relative path tag: @path/to/file.ext:start-end"
|
||||||
(interactive)
|
(interactive)
|
||||||
(if (use-region-p)
|
(let ((tag (my--get-region-as-path-tag
|
||||||
(let* ((filename (file-relative-name (buffer-file-name) (doom-project-root)))
|
(lambda () (file-relative-name (buffer-file-name) (doom-project-root))))))
|
||||||
(start-line (line-number-at-pos (region-beginning)))
|
|
||||||
;; If region ends at beginning of a line, we want the previous line
|
|
||||||
(end-pos (1- (region-end)))
|
|
||||||
(end-line (line-number-at-pos (max (region-beginning) end-pos)))
|
|
||||||
(tag (format "@%s:%d-%d" filename start-line end-line)))
|
|
||||||
(kill-new tag)
|
(kill-new tag)
|
||||||
(message "Copied: %s" tag))
|
(message "Copied: %s" tag)))
|
||||||
(let* ((filename (file-relative-name (buffer-file-name) (doom-project-root)))
|
|
||||||
(line (line-number-at-pos))
|
(defun my/copy-region-as-path-tag-absolute ()
|
||||||
(tag (format "@%s:%d" filename line)))
|
"Copy the current region as an absolute path tag: @/abs/path/to/file.ext:start-end"
|
||||||
|
(interactive)
|
||||||
|
(let ((tag (my--get-region-as-path-tag #'buffer-file-name)))
|
||||||
(kill-new tag)
|
(kill-new tag)
|
||||||
(message "Copied: %s" tag))))
|
(message "Copied: %s" tag)))
|
||||||
|
|
||||||
;; Add keybindings for helper functions
|
;; Add keybindings for helper functions
|
||||||
(map! :leader
|
(map! :leader
|
||||||
(:prefix "A"
|
(:prefix "A"
|
||||||
:desc "Quick explain" "e" #'my/gptel-quick-explain-region
|
:desc "Quick explain" "e" #'my/gptel-quick-explain-region
|
||||||
:desc "Proofread text" "p" #'my/gptel-proofread-region
|
:desc "Proofread text" "p" #'my/gptel-proofread-region
|
||||||
:desc "Copy path tag" "t" #'my/copy-region-as-path-tag))
|
:desc "Copy path tag (relative)" "t" #'my/copy-region-as-path-tag
|
||||||
|
:desc "Copy path tag (absolute)" "T" #'my/copy-region-as-path-tag-absolute))
|
||||||
|
|
||||||
;;; Claude Code Configuration
|
;;; Claude Code Configuration
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user