8

Q: How can I stop underlining through the left "margin" in links that extend over more than one line?

The face org-link inherits from the face link, which has the underline attribute set to t (or at least it does by default). Ordinarily, that's all well and good. It gets ugly, however, if the description of the link is sufficiently long that it wraps onto more than one line, as in the following screenshot:

org-mode links

The screenshot shows the underlining extending from the left margin all the way to indentation. That's a pretty ugly visual tick. Is there any way to keep underlining for links, and yet not have the underlining extend from the margin in this way?

  • 1
    If you find a solution that you like, then please share it with the org maintainers because it will probably end up in the mainline: orgmode.org/community.html – grettke Dec 31 '14 at 1:53
3

I've messed around a bit with org-activate-bracket-links. I'm not really an expert in font-locking, so I only managed to make the "^ +" part of the link invisible:

(defun org-activate-bracket-links (limit)
  "Add text properties for bracketed links."
  (if (and (re-search-forward org-bracket-link-regexp limit t)
           (not (org-in-src-block-p)))
      (let* ((hl (org-match-string-no-properties 1))
             (help (concat "LINK: " (save-match-data (org-link-unescape hl))))
             (ip (org-maybe-intangible
                  (list 'invisible 'org-link
                        'keymap org-mouse-map 'mouse-face 'highlight
                        'font-lock-multiline t 'help-echo help
                        'htmlize-link `(:uri ,hl))))
             (vp (list 'keymap org-mouse-map 'mouse-face 'highlight
                       'font-lock-multiline t 'help-echo help
                       'htmlize-link `(:uri ,hl))))
        ;; We need to remove the invisible property here.  Table narrowing
        ;; may have made some of this invisible.
        (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
        (remove-text-properties (match-beginning 0) (match-end 0)
                                '(invisible nil))
        (if (match-end 3)
            (progn
              (add-text-properties (match-beginning 0) (match-beginning 3) ip)
              (org-rear-nonsticky-at (match-beginning 3))
              (add-text-properties (match-beginning 3) (match-end 3) vp)
              (org-rear-nonsticky-at (match-end 3))
              (add-text-properties (match-end 3) (match-end 0) ip)
              (org-rear-nonsticky-at (match-end 0))
              (let ((b3 (match-beginning 3))
                    (e3 (match-end 3)))
                (save-excursion
                  (save-match-data
                    (goto-char b3)
                    (while (re-search-forward "\\(?:^ +\\| +$\\)" e3 t)
                      (org-rear-nonsticky-at (match-beginning 0))
                      (add-text-properties (match-beginning 0)
                                           (match-end 0) ip)
                      (org-rear-nonsticky-at (match-end 0)))))))
          (add-text-properties (match-beginning 0) (match-beginning 1) ip)
          (org-rear-nonsticky-at (match-beginning 1))
          (add-text-properties (match-beginning 1) (match-end 1) vp)
          (org-rear-nonsticky-at (match-end 1))
          (add-text-properties (match-end 1) (match-end 0) ip)
          (org-rear-nonsticky-at (match-end 0)))
        t)))
  • Thanks for the suggestion. Although it does eliminate the unsightly underlining from the left margin, unfortunately, the text of the second line is now flush to the left margin instead. I'll try to poke around a little bit more. – Dan Dec 31 '14 at 16:17

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.