0

I've been trying to hide the URL component of the markdown links in my buffer.

I could select the markdown links using

"\\(\\[.+\\]\\)\\((.+)\\)"

However, I just want to capture the second half (the URL component) of the links and fade them away in the buffer.

I have tried every possible documentation available but with no avail. Please help.

  • You should add ? to your reqular expressions to avoid greedy matching, i.e., "\(\[.+?\]\)\((.+?)\)". – Tobias Nov 7 '16 at 11:22
  • To capture the second half of the re just use the right subexpressions, such as (match-beginning 1) and (match-end 1). – Tobias Nov 7 '16 at 11:24
  • I have tried that as well, could you please provide one example? – myTerminal Nov 7 '16 at 11:26
  • It does not seem to identify the sub-expressions, I tried \(\[.+?\]\)\((.+?)\)(match-end 1) – myTerminal Nov 7 '16 at 11:31
1

The following minimal example code shows how to hide the urls in md-files:

(defun md-hide-urls ()
  "Hide all urls in the current buffer."
  (interactive)
  (goto-char (point-min))
  (while (re-search-forward "\\(\\[.+\\]\\)\\((.+)\\)" nil t)
    (put-text-property (match-beginning 2) (match-end 2) 'invisible t)))

Regular expression search via lisp is described in Section 33.4 of the emacs manual. How to make text invisible is described in Section 37.6 of the emacs manual. You find informations on accessing match strings in Section 37.6.2 of the emacs manual.

  • Thanks. I've been looking (highlight-regexp <reg-exp> <face>). I highly doubt I could use it there. – myTerminal Nov 7 '16 at 12:19
  • 1
    @myTerminal AFAIK there is no face having the same effect as the invisibility text property. See also: emacs.stackexchange.com/questions/13343/… – Tobias Nov 7 '16 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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