Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing text appearance in Emacs: overlays work, text properties don't

Tags:

emacs

overlays

I've been experimenting today with text properties in Emacs. If I position the cursor on a line with some text on it and then execute the following code with M-:, the line is redisplayed in bold.

(overlay-put
 (make-overlay
  (line-beginning-position)
  (line-end-position))
 'face 'bold)

If, however, I wipe out the overlay with (remove-overlays) and execute the following code, nothing happens (except that the word "nil" appears in the minibuffer).

(put-text-property
 (line-beginning-position)
 (line-end-position)
 'face 'bold)

From what I've gleaned so far, I'd expect that these two snippets should produce the same visual results. Why don't they?

like image 510
Sean Avatar asked Feb 11 '10 04:02

Sean


2 Answers

When font-lock-mode is on, the face attribute will be overridden. Try font-lock-face instead:

(put-text-property
 (line-beginning-position)
 (line-end-position)
 'font-lock-face 'bold)
like image 179
huaiyuan Avatar answered Oct 17 '22 15:10

huaiyuan


ansi-color.el -- "In Emacs, however, things are a bit different: When font-lock is active in a buffer, you cannot simply add face text-properties to the buffer. Font-lock will remove the face text-property using 'font-lock-unfontify-region-function'. If you want to insert the strings returned by 'ansi-color-apply' into such buffers, you must set 'font-lock-unfontify-region-function' to `ansi-color-unfontify-region'. This function will not remove all face text-properties unconditionally. It will keep the face text-properties if the property 'ansi-color' is set.

like image 29
Chris Avatar answered Oct 17 '22 14:10

Chris