25 votes
Accepted

How to strip decorations (text properties) from a string?

[Your propertized string looks wrong - perhaps you copied it wrong. foo has only 3 characters, so it is impossible for it to be fontified on chars 0 to 4 (i.e., chars 0, 1, 2, and 3 - that's 4 chars)....
user avatar
  • 70.3k
16 votes
Accepted

What are overlays for, and how do they differ from text properties?

What are Overlays? First of all, they are elisp objects. This will be relevant later. As you said yourself, they represent layers that apply on top of regions of the buffer. These layers have text ...
user avatar
  • 22.4k
14 votes
Accepted

Strip text properties in savehist

Add the following to your init-file: (defun unpropertize-kill-ring () (setq kill-ring (mapcar 'substring-no-properties kill-ring))) (add-hook 'kill-emacs-hook 'unpropertize-kill-ring) How it ...
user avatar
  • 14.3k
11 votes
Accepted

Can I use an image in my modeline lighter?

The mode line is rendered from a list of segments, each of which come with their own special rules. See Mode Line Data for the details. The symbol section contains a crucial hint to make your code ...
user avatar
  • 21.1k
10 votes
Accepted

Prevent inserting text at the beginning of a buffer that starts with read-only text

You need to (before adding property read-only), make the first character have a value that includes read-only for property front-sticky: (put-text-property 1 2 'front-sticky '(read-only)) ; Do this ...
user avatar
  • 70.3k
7 votes

How does AucTeX display superscripts?

Use the raise display property. As explained in (info "(elisp) Other Display Specs"): `(raise FACTOR)' This kind of display specification raises or lowers the text it applies to, relative ...
user avatar
  • 6,691
7 votes

Are there any libraries for input fields in Emacs?

See libraries cus-edit.el and wid-edit.el (and their top-level libraries custom.el and widget.el, and associated component libraries), which are included with GNU Emacs. The former makes use of the ...
user avatar
  • 70.3k
7 votes
Accepted

Why does mousing over one button also highlight adjacent buttons?

Buttons are based on text properties. Each character in a buffer has its own properties. Emacs doesn't record start and end positions for properties: properties are not intervals. When it needs to ...
user avatar
6 votes
Accepted

How to set the glyph of a unicode character?

What you want to do is to set the display-table entry for character LEFT-TO-RIGHT EMBEDDING to the glyph that is used for character SECTION SIGN. (aset (or (window-display-table) standard-display-...
user avatar
  • 70.3k
6 votes

Strip text properties in savehist

One simple solution is to use savehist-20.el. It is a version of savehist.el that works with all Emacs versions (20+). It automatically strips history elements of properties, and it does not save ...
user avatar
  • 70.3k
6 votes
Accepted

How to apply overlay or text properties to text matching a regexp?

Yes, it’s possible A couple of points on your function: Don’t cut the text before you need it. Use the third argument for search-forward-regexp to avoid getting errors. And so: (defun source-to-...
user avatar
  • 22.4k
6 votes
Accepted

Temporary text in window location with no text to propertize/overlay?

I've whipped up a working example of a function that takes a string and temporarily displays it with a timeout after the buffer text: (defun my-momentarily-display-after-buffer-end (string &...
user avatar
  • 21.1k
6 votes
Accepted

How to remove all text properties in a buffer

Maybe this: (let ((inhibit-read-only t)) (set-text-properties (point-min) (point-max) nil))
user avatar
  • 13.6k
6 votes
Accepted

Why does `insert` not insert colorized text?

You probably try that in the *scratch* buffer or any other buffer with active font-lock-mode. In such a buffer the faces are immediately adapted to the rules prescribed by the variable font-lock-...
user avatar
  • 30.5k
5 votes
Accepted

How to make mode-line text look like a link/button on hover

You can use the mouse-face property. For example, the following snippet will make "f" look like a button when you hover the mouse pointer over it: (setq mode-line-format (list (propertize ...
user avatar
5 votes
Accepted

Prevent Emacs from asking "kill anyway" when only text properties have changed

If you only care about changes that occur in this function, you can use buffer-modified-p and set-buffer-modified-p to store the modified state and restore it after changing the properties.
user avatar
  • 404
5 votes

compose-region and TABs

As far as I understand, compose-region and the underlying composition text property can only result in displaying a single glyph (which may be built from several parts). When you pass multiple glyphs, ...
user avatar
5 votes
Accepted

Make parts of a working buffer read-only

(defface my-read-only '((default . (:background "beige"))) "Face for `my-read-only-region'") (defun my-read-only-region (begin end) "Make the marked region read-only. See also `my-writeable-...
user avatar
  • 43.9k
4 votes
Accepted

Ways to unobtrusively vary text rendering?

Another possibility would be to display line numbers and say the line number before the word, or, since looking over to get the exact line number would be bothersome, you could have the algorithm ...
user avatar
4 votes
Accepted

Make all text of a given face invisible

OK, here's a simple demonstration of @Lindydancer's technique, which in this case turns the whole buffer invisible. (defun my-mode () "my-mode" (interactive) (kill-all-local-variables) (make-...
user avatar
  • 301
4 votes
Accepted

Add clickable text in read only buffer?

The reason for the error is that you did not use the correct format to add a text property. quote from manual: Function: add-text-properties start end props &optional object The argument props ...
user avatar
  • 360
4 votes

Can I use an image in my modeline lighter?

Good question. You might try using something like this as the lighter: (concat " " (propertize " " 'display (create-image img-file))), where img-file is the name of your image file. (The first space ...
user avatar
  • 70.3k
4 votes
Accepted

How to get an insert-text-button 'action property accessing a dynamically-bound buffer-local variable

You can add not only action but any other attributes to a text-button, that can be referred later with button-get function. So saving the (reference to the) current buffer, together with action, seems ...
user avatar
  • 446
4 votes
Accepted

Text as text properties?

You can put any Lisp object (thingie) on a character as a text property or on in an overlay as an overlay property or on a symbol as a symbol property. You speak of "strings" but in your examples I ...
user avatar
  • 70.3k
4 votes

New line in cursor-intangible area and line-beginning position

Applying field property to intangible area solves the problem. Adding of field t to the properties of INTANGIBLE makes move-beginning-of-line putting point between INTANGIBLE and fooooo, like ...
user avatar
4 votes

Can Emacs enriched-text be displayed by other applications, browsers?

The etc/enriched.txt file points out that the basic file format is the text/enriched MIME format described by RFC1896: https://www.ietf.org/rfc/rfc1896.txt Enriched-mode documents are saved in an ...
user avatar
  • 43.9k
3 votes
Accepted

Get width of an image

See the documentation on the function image-size: image-size is a built-in function in `C source code'. (image-size SPEC &optional PIXELS FRAME) Return the size of image SPEC as pair (WIDTH . ...
user avatar
  • 10.1k
3 votes
Accepted

How to use the highlight-chars.el package?

@Malabarba's comment provides the answer. Try it interactively: M-x hc-highlight-chars. It works for me. I use C-x 8 RET LEFT-TO-RIGHT EMBEDDING RET to insert character LRE (U+202A) in a buffer. ...
user avatar
  • 70.3k

Only top scored, non community-wiki answers of a minimum length are eligible