1

I am searching in a buffer for a regular expression by this snippet:

(setq jb-revision-version "\\([[:digit:]]+\\.?\\)")
(setq jb-revision-string "\\(\\(Revision\\|Id\\): +\\)")
(progn
  (save-excursion
    (goto-char (point-min))
    (setq start (re-search-forward jb-revision-string)
      end (re-search-forward (concat jb-revision-version "+")))
    (setq version (buffer-substring start end))))

The result in variable version is this:

version
#("0.1.2" 0 5 (face font-lock-comment-face fontified nil))

What I want, is the pure string "0.1.2" in this case.

Even if I insert (font-lock-mode -1) ... (font-lock-mode 1) in my above code, the result still contains some font-lock-info:

#("0.1.2" 0 5 (fontified nil))

I haven't found any font-lock-to-string function, to get rid of that stuff. Neither did I find a command, to temporarily defontify the buffer before searching.

I haven't found any hints in the Emacs, Emacs-Lisp or the Lisp-Introduction Info manuals.

  • 1
    does it work to use buffer-substring-no-properties? the description for the buffer-substring function says it returns text properties as well as the characters. – shoshin Dec 30 '19 at 15:48
  • @shoshin YES! Would you please write it as answer, that I can mark this question solved and give you the credit you deserve? – Jan Dec 30 '19 at 15:51
2

You'll want to use the function buffer-substring-no-properties. In the documentation for M-x describe-function buffer-substring it says this:

This function copies the text properties of that part of the buffer into the result string; if you don’t want the text properties, use buffer-substring-no-properties instead.

| improve this answer | |

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.