customizing org-insert-link to insert links with maximum efficiency reddit / emacs ---------------------------------------------------------------------- costis-t · 2022-02-18 17:45 In Doom Emacs, how do I customize org-insert-link? I want it to leave one or two spaces before and after the link. I have tried various variations of the below but doesn't seem to work `(defun org-insert-link-with-space ()` `"org-insert-link-with-space, like org-insert-link but after prompt"` `(interactive)` `(insert " ") (org-insert-link) (insert " ") (evil-insert-state)` `)` `(map! :ne "SPC m l" #'org-insert-link-with-space)` I want to type this: here is a **link** for you pressing the minimum amount of keys: hereisamllforyou ​ I've also asked in emacs.stackexchange but there was no answer. ---------------------------------------------------------------------- BobKoss · 2022-02-18 19:10 Perhaps try the string concatenation function, (cons …) build your final string from the 3 parts and then insert the final string. I’m just guessing but it’s what I would try next. ---------------------------------------------------------------------- nv-elisp · 2022-02-18 19:16 > I've also asked in emacs.stackexchange but there was no answer. You asked approximately a day ago. Exercise patience when asking strangers to volunteer their support. ---------------------------------------------------------------------- costis-t · 2022-02-19 17:42 Thanks! I 'll google it. I 'll wait a few more days and if this doesn't work it'll be good time to get some coherent education (https://www.gnu.org/software/emacs/manual/pdf/eintr.pdf) on emacs lisp instead of relying on simple google searches. ---------------------------------------------------------------------- organic-bookworm · 2022-02-19 21:09 The function itself works fine, the problem is the binding. See how Doom [binds](https://github.com/hlissner/doom-emacs/blob/84967 2691dd5d1214d6c72167ae84c03e8d9c8e3/modules/lang/org/config.el#L937) `org-insert-link` to `SPC m l l`, if you wanted to bind it only in `org-mode`. It roughly boils down to the following: (map! :after org ;; bind after loading `org' :map org-mode-map ;; use `org-mode` keymap :localleader ;; respect `doom-localleader-key' and `doom- localleader-alt-key', don't hardcode "SPC m" and "M-SPC m" :ni "ll" #'org-insert-link-with-space ;; will only bind with `evil-mode' in place ) ---------------------------------------------------------------------- costis-t · 2022-02-19 22:50 Thanks all for your input and your care. I have a working function which I'll upload after I do an animated gif in a couple of days. Thanks again! ---------------------------------------------------------------------- costis-t · 2022-02-20 23:29 Eventually, I figured out how to do it. Searching in dark (=ignorant of elisp): `(add-hook 'post-self-insert-hook` `(lambda ()` `(and (eq last-command-event ?k)` `(looking-back "jk" (- (point) 2))` `(if (> 1 2)` `(message "True")` `(call-interactively 'evil-delete-backward-char)` `(call-interactively 'evil-delete-backward-char)` `(call-interactively 'org-insert-link)` `))))` And a small gif which demonstrates it: [https://i.stack.imgur.com/bFep F.gif](https://i.stack.imgur.com/bFepF.gif) Thanks all!