5

It must be very simple to get rid of but I could not find something addressing the problem : I would like to avoid underlined spaces between two lines. The following screenshot illustrates the problem in an org itemize: enter image description here

I use the classic default-fill-column of 80.

The describe-char value of the space character (in place of the red cursor) gives the following:

 position: 500 of 1353 (37%), column: 0
        character: SPC (displayed as SPC) (codepoint 32, #o40, #x20)
preferred charset: ascii (ASCII (ISO646 IRV))
code point in charset: 0x20
           script: latin
           syntax:          which means: whitespace
         category: .:Base, a:ASCII, l:Latin
         to input: type "C-x 8 RET HEX-CODEPOINT" or "C-x 8 RET NAME"
      buffer code: #x20
        file code: #x20 (encoded by coding system utf-8-unix)
          display: terminal code #x20

Character code properties: customize what to show
  name: SPACE
  general-category: Zs (Separator, Space)
  decomposition: (32) (' ')

There are text properties here:
  face                 org-link
  font-lock-multiline  t
  fontified            t
  help-echo            [Show]
  keymap               [Show]
  mouse-face           highlight

EDIT (by Tobias): Org-text for reproduction:

- Energy and Numerical Weather Predictin; aussi ce papier sur [[http://web.mit.edu/lorenzcenter/about/LorenzPubs/The_Statistical_Prediction_of_Solutions_1962.pdf][statistic
  prediction of sol of dynamics equations]]

Local Variables:
fill-column: 80
org-hide-emphasis-markers: t
eval: (progn (setq org-descriptive-links nil) (org-toggle-link-display))
End:
  • Is this in org-mode ? – Håkon Hægland Nov 20 '16 at 12:29
  • Yes, this is in org-mode, I forgot to specify it. – loukios Nov 20 '16 at 13:02
  • Note that default-fill-column is obsolete (see its docstring, pointing to fill-column instead). – JeanPierre Nov 20 '16 at 14:57
  • Have you activated org-hide-emphasis-markers, and org-descriptive-links? Did you use underlining, i.e. _text_ on the underlined text? – Tobias Nov 20 '16 at 15:04
  • @Tobias, yes org-hide-emphasis-markers is enabled. In my example, the underlining is the result of a link, but I got the same result with the "underlined" markup. – loukios Nov 20 '16 at 17:50
1

Putting the following lisp-snippet into your initialization file (e.g., ~/.emacs) should do the job.

It puts a fontification rule at the very end of the org-specific font-lock-keywords. This rule clears underlining of spaces at line-beginnings by overriding the faces there.

(defface org-dont-underline-indents '((t :underline nil))
  "Avoid underlining of indentation.")

(defun org-dont-underline-indents ()
  "Remove underlining at indents."
  (add-to-list 'org-font-lock-extra-keywords '("^[[:space:]]+" 0 'org-dont-underline-indents t) 'append))

(add-hook 'org-font-lock-set-keywords-hook #'org-dont-underline-indents 'append)

The above version is greedy in the sense that it adds the org-dont-underline-indents face to all (non-empty) indents.

If this has any negative consequences I am not aware of yet you can use the following version that only adds the org-dont-underline-indents face if it finds some other face at the beginning of the indent.

(defface org-dont-underline-indents '((t :underline nil))
  "Avoid underlining of indentation.")

(defun org-search-underlined-indents (limit)
  "Match function for `org-dont-underline-indents'."
  (let (ret face)
    (while (and (setq ret (re-search-forward "^[[:space:]]+" limit t))
        (or (null (setq face (plist-get (text-properties-at (match-beginning 0)) 'face)))
            (eq face 'org-dont-underline-indents))))
    ret))

(defun org-dont-underline-indents ()
  "Remove underlining at indents."
  (add-to-list 'org-font-lock-extra-keywords '(org-search-underlined-indents 0 'org-dont-underline-indents t) 'append))

(add-hook 'org-font-lock-set-keywords-hook #'org-dont-underline-indents 'append)
  • Thanks for your proposition. I may have not phrased the issue correctly enough, it's not really bound to an itemize context but rather to any line break. I will try to adapt your code to this general situation. – loukios Nov 22 '16 at 9:38
  • @loukios "Indent" is not "itemize". It should work for any line beginning with a non-empty sequence of whitespaces. If you have issues with the code please leave a comment here and I will see what I can do with my limited time-ressources. – Tobias Nov 22 '16 at 9:40

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.