branch: elpa/markdown-mode commit 2645b7fd148eb8d5c2d141cf49ccbf1775275195 Author: Joe Reinhart <joseph.reinh...@gmail.com> Commit: Joe Reinhart <joseph.reinh...@gmail.com>
Add markdown-missing-link-face when appropriate to parts of wiki links --- markdown-mode.el | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/markdown-mode.el b/markdown-mode.el index 4e9a184bfa..bebcbc9396 100644 --- a/markdown-mode.el +++ b/markdown-mode.el @@ -3384,13 +3384,14 @@ the buffer)." (defun markdown-fontify-wiki-links (last) "Add text properties to next wiki link from point to LAST." (when (and markdown-enable-wiki-links - (not markdown-wiki-link-fontify-missing) (markdown-match-inline-generic markdown-regex-wiki-link last)) - (let ((begin (match-beginning 1)) - (end (match-end 1)) - (aliasp (string-equal (match-string-no-properties 4) "|")) - (part1 (match-string-no-properties 3)) - (part2 (match-string-no-properties 5))) + (let* ((begin (match-beginning 1)) + (end (match-end 1)) + (aliasp (string-equal (match-string-no-properties 4) "|")) + (part1 (match-string-no-properties 3)) + (part2 (match-string-no-properties 5)) + (file-name (markdown-convert-wiki-link-to-filename (markdown-wiki-link-link))) + (file-missing-p (not (file-exists-p file-name)))) (if (or (markdown-in-comment-p begin) (markdown-in-comment-p end) (markdown-inline-code-at-pos-p begin) @@ -3402,17 +3403,26 @@ the buffer)." ;; Add text properties for hiding markup (progn (if aliasp - (if markdown-wiki-link-alias-first + (progn + ;; Propertize pipe separating URL from link text + (add-text-properties (match-beginning 4) (match-end 4) markup-props) + (if markdown-wiki-link-alias-first + (progn + (if (and file-missing-p markdown-wiki-link-fontify-missing) + (add-text-properties (match-beginning 3) (match-end 3) (missing-link-props part2)) + (add-text-properties (match-beginning 3) (match-end 3) (link-props part2))) + (add-text-properties (match-beginning 5) (match-end 5) url-props)) (progn - (add-text-properties (match-beginning 3) (match-end 3) (link-props part2)) - (add-text-properties (match-beginning 5) (match-end 5) url-props)) - (progn - (add-text-properties (match-beginning 3) (match-end 3) url-props) - (add-text-properties (match-beginning 5) (match-end 5) (link-props part1)))) - (add-text-properties (match-beginning 3) (match-end 3) (link-props part1))) + (add-text-properties (match-beginning 3) (match-end 3) url-props) + (if (and file-missing-p markdown-wiki-link-fontify-missing) + (add-text-properties (match-beginning 5) (match-end 5) (missing-link-props part1)) + (add-text-properties (match-beginning 5) (match-end 5) (link-props part1)))))) + (if (and file-missing-p markdown-wiki-link-fontify-missing) + (add-text-properties (match-beginning 3) (match-end 3) (missing-link-props part1)) + (add-text-properties (match-beginning 3) (match-end 3) (link-props part1)))) + ;; Propertize opening and closing brackets (add-text-properties (match-beginning 2) (match-end 2) markup-props) - (add-text-properties (match-beginning 6) (match-end 6) markup-props) - (add-text-properties (match-beginning 4) (match-end 4) markup-props)) + (add-text-properties (match-beginning 6) (match-end 6) markup-props)) (set-match-data (list begin end)) t)))) @@ -8216,6 +8226,14 @@ Translate filenames using `markdown-filename-translate-function'." 'font-lock-multiline t 'help-echo echo-text))) +(defun missing-link-props (url) + "Return a property list for URL for file that doesn't exist." + (list 'face 'markdown-missing-link-face + 'keymap 'markdown-mode-mouse-map + 'mouse-face 'markdown-highlight-face + 'font-lock-multiline t + 'help-echo url)) + (defun markdown-fontify-inline-links (last) "Add text properties to next inline link from point to LAST." (when (markdown-match-generic-links last nil)