Elisp newbie here,

I am trying to filter MS safelinks from an org-mode icalendar event, which gets saved by the gnus-icalendar:org-event-save function. I have created a function that filters the MS safelinks and am now trying to apply it to the buffer created inside gnus-icalendar:org-event-save. I have tried unsuccessfully to 1) run it as a hook, and 2) re-define the function as

(defun gnus-icalendar:org-event-save (event reply-status)
    (org-capture-string (gnus-icalendar-event->org-entry event reply-status)
    (unsafelinks nil)))

When I have MS safelinks in *scratch* and eval (unsafelinks nil) the links get filtered, so I don't understand why the above setup doesn't work. Probably it is an obvious mistake from someone learning elisp. Thank you in advance.


Per request of wasamasa, the text to be filtered out is returned by the function (gnus-icalendar-event->org-entry event reply-status).

  • 1
    Try adding unsafelinks to org-capture-prepare-finalize-hook, does that do the trick?
    – wasamasa
    Commented Sep 4, 2020 at 14:13
  • Aside, it would help to know what text exactly needs filtering. The initial text provided to the capture buffer by (gnus-icalendar-event->org-entry event reply-status)? The text you enter there yourself?
    – wasamasa
    Commented Sep 4, 2020 at 14:14
  • "I have created a buffer-local function" -- there is no such thing as a buffer-local function. Only variables can be buffer-local. You could assign a function object to a buffer-local variable, but it's really not clear what you actually meant.
    – phils
    Commented Sep 4, 2020 at 14:20
  • Sweet @wasamasa. The org-capture-prepare-finalize-hook was spot on. Thank you very much! THis is what I've used (add-hook 'org-capture-prepare-finalize-hook (lambda () (unsafelinks nil)) t). Add it to a reply and I'll accept it
    – Ajned
    Commented Sep 4, 2020 at 14:26
  • Thanks for letting me know @phils. I'll edit the question accordingly.
    – Ajned
    Commented Sep 4, 2020 at 14:28

1 Answer 1


I'm not sure at what point your text comes in, but since this is org-capture, you can use org-capture-prepare-finalize-hook to do postprocessing like this:

(add-hook 'org-capture-prepare-finalize-hook (lambda () (unsafelinks nil)))

Note that this does the postprocessing globally, so consider using the fourth argument of add-hook to do it locally or write a named hook function removing itself from the hook after it's done.

edit: In light of the update, here's an alternative way of doing this without hooks:

(defun unsafelinks-string (string vmode)
    (insert string)
    (unsafelinks vmode)

(with-eval-after-load 'gnus-icalendar
  (defun gnus-icalendar:org-event-save (event reply-status)
      (org-capture-string (unsafelinks-string
                           (gnus-icalendar-event->org-entry event reply-status)
  • Sorry for my lack of clarity. I've detailed what text I want to have filtered out. Will add that to the question.
    – Ajned
    Commented Sep 4, 2020 at 15:43
  • The alternative does not work. It is missing vmode in gnus-icalendar:org-event-save (which can be nil for the present case), but aside from that, the links are not being filtered.
    – Ajned
    Commented Sep 4, 2020 at 19:51
  • Found the issue and it's my fault. I should have called (beggining-of-buffer) before the search for urls in unsafelinks. With that modification your alternative solution works 100%. Just learned something new, and I will update the unsafelinks function in my other post. Thanks once again.
    – Ajned
    Commented Sep 4, 2020 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.