This commit is contained in:
@@ -69,7 +69,8 @@
|
|||||||
(general-def
|
(general-def
|
||||||
:prefix-map 'syd-leader-insert-map
|
:prefix-map 'syd-leader-insert-map
|
||||||
"u" #'insert-char
|
"u" #'insert-char
|
||||||
"e" #'emoji-insert)
|
"e" #'emoji-insert
|
||||||
|
"p" #'syd-insert-file-name)
|
||||||
|
|
||||||
;; This is necessary to properly rebind `universal-argument'.
|
;; This is necessary to properly rebind `universal-argument'.
|
||||||
;; `universal-argument-more' is a command that provides additional prefixes
|
;; `universal-argument-more' is a command that provides additional prefixes
|
||||||
|
|||||||
@@ -193,4 +193,38 @@ form."
|
|||||||
(cons mode (intern (concat (match-string 1 s) "-ts-mode"))))
|
(cons mode (intern (concat (match-string 1 s) "-ts-mode"))))
|
||||||
(error "Symbol `%c' is not a mode." mode))))
|
(error "Symbol `%c' is not a mode." mode))))
|
||||||
|
|
||||||
|
(defun syd--insert-file-name-annotation (x)
|
||||||
|
(concat
|
||||||
|
" "
|
||||||
|
(propertize " " 'display `(space :align-to (- right ,(+ 1 (length x)))))
|
||||||
|
x))
|
||||||
|
|
||||||
|
(defun syd-insert-file-name ()
|
||||||
|
(interactive)
|
||||||
|
(let* ((path (read-file-name "Path: " nil nil 'confirm))
|
||||||
|
(proj-root (project-root (project-current)))
|
||||||
|
(alts
|
||||||
|
`((,(file-relative-name path proj-root) . "Project-relative")
|
||||||
|
(,(file-relative-name path default-directory) . "File-relative")
|
||||||
|
(,path . "Absolute")
|
||||||
|
("... (choose a dir)")))
|
||||||
|
(choice
|
||||||
|
(completing-read
|
||||||
|
"Variant: "
|
||||||
|
(lambda (s p flag)
|
||||||
|
(pcase flag
|
||||||
|
('metadata
|
||||||
|
`(metadata
|
||||||
|
(annotation-function
|
||||||
|
. ,(lambda (s)
|
||||||
|
(when-let* ((desc (cdr (assoc s alts))))
|
||||||
|
(syd--insert-file-name-annotation
|
||||||
|
desc))))))
|
||||||
|
(_ (all-completions s (mapcar #'car alts) p)))))))
|
||||||
|
(if (equal choice "... (choose a root)")
|
||||||
|
(insert (file-relative-name
|
||||||
|
path (read-file-name "Relative to: " nil nil
|
||||||
|
'confirm)))
|
||||||
|
(insert choice))))
|
||||||
|
|
||||||
(provide 'syd/prelude)
|
(provide 'syd/prelude)
|
||||||
|
|||||||
Reference in New Issue
Block a user