# In emacs markdown-mode making the link live and URL invisible in inline links

A few years ago I modified version 1.8.1 of Jason Blevins's markdown-mode for Emacs so that when showing inline links the URL is hidden, and so that you can follow the link simply by hitting Enter. If you want to see the URL you can still see it by, say, removing the final ). It's based on linkd, though I'm told that org-mode's org-activate-bracket-links achieves something similar.

I'm sure there are potential areas for improvement in my code for a number of reasons:

1. I'm still learning Elisp
2. It seems like I should have been able to accomplish the task with less code
3. When I try to port the code to the newest version of markdown-mode (version 2.0; available here for the moment), it breaks in a confusing way
4. My code doesn't play nicely with adaptive-wrap; I don't get a hanging indent for lines that start in the middle of a URL

I've posted my code at http://pastebin.com/AqQSqeWM, but the change consists only of changing

   (cons markdown-regex-link-inline
(2 markdown-url-face t)))


to

   (cons markdown-regex-link-inline
'((0 (let
(url-beg (match-beginning 2))
(url-end (match-end 2)))
prepend)))


and then tack on this code somewhere:

(defun markdown-linkd-follow-at-point ()
(interactive)
(loop for ov in (overlays-at (point)) do
(when url
(browse-url url)))))

(interactive "e")
(when event
(select-window (posn-window (event-start event)))
(set-buffer (window-buffer (posn-window (event-start event))))
(goto-char (posn-point (event-start event)))

(loop for ov in (overlays-at loc)

;; It's not enough to mark links with a text property because text properties get copied and overlays do not
(let ((url (buffer-substring-no-properties (1+ url-beg) (1- url-end)))
(display-text (concat
"()")))

(defun markdown-linkd-overlay (beg end url display-text display-face)
(let ((overlay (make-overlay beg end))
(overlay-modification-code
(list (lambda (ov foo beg end &rest ignore)
(delete-overlay ov)
))))
(overlay-put
;; Could maybe use invisible text rather than display-text, but this
;; way makes it easy to also get a live link with a single overlay
overlay 'display (propertize display-text
'face display-face