You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wrote this command for faster linking of files in org-mode. In other modes it inserts relative filenames. Please, let me know what you think about it.
;; Fast and convenient file links with Embark
(defcustom embark-file-link-separator """A string separator to insert after the link.":type'string)
(defcustom embark-file-link-filename-replace-chars (list ?_ ?-)
"Characters in file names to replace with spaces.":type'list)
(defunembark-file-insert-link-dwim-get-title (filename)
"Converts a FILENAME to a link tiltle."
(let ((short-fname (file-name-sans-extension (file-name-nondirectory filename))))
(dolist (ch embark-file-link-filename-replace-chars)
(subst-char-in-string ch ?\ short-fname t))
short-fname))
(defunembark-file-insert-link-dwim (file)
(let ((link-text "")
(separator embark-file-link-separator))
(cond;; in org-mode insert org-link
((equal major-mode 'org-mode)
(if (not (region-active-p))
(setq link-text (concat "[" (embark-file-insert-link-dwim-get-title file) "]"))
(setq link-text (concat "[" (buffer-substring (region-beginning) (region-end)) "]"))
(kill-region (region-beginning) (region-end))
(setq separator ""))
(insert (if (cl-search default-directory (expand-file-name file))
(format"[[./%s]%s]" (file-relative-name file) link-text)
(format"[[%s]%s]" (f-abbrev file) link-text))))
;; in other modes insert relative path
(t
(embark-insert-relative-path file)))
(insert separator)))
(keymap-set embark-file-map "TAB"#'embark-file-insert-link-dwim)
The text was updated successfully, but these errors were encountered:
I wrote this command for faster linking of files in org-mode. In other modes it inserts relative filenames. Please, let me know what you think about it.
The text was updated successfully, but these errors were encountered: