I have the following function to print the line where point is to the *scratch* buffer,
(defun print-line ()
(print (thing-at-point 'line) (get-buffer "*scratch*")))
but it prints even the fontified info like this
#(" OFFICE
" 0 2 (fontified t org ...
How to discard the printing of the fontified info.
To expand on Daimrod's mention of buffer-substring-no-properties
...
M-x apropos
RET no-properties
RET
buffer-substring-no-properties
Function: Return the characters of part of the buffer, without the
text properties.
field-string-no-properties
Function: Return the contents of the field around POS, without text
properties.
insert-buffer-substring-no-properties
Function: Insert before point a substring of BUFFER, without text
properties.
match-string-no-properties
Function: Return string of text matched by last search, without text
properties.
minibuffer-contents-no-properties
Function: Return the user input in a minibuffer as a string, without
text-properties.
substring-no-properties
Function: Return a substring of STRING, without text properties.
You can read about text properties in the manual:
M-: (info "(elisp) Text Properties") RET
I needed something similar for eredis when manipulating strings from an org-table. You can use `set-text-properties' to get rid of them when displaying the string.
(defun strip-text-properties(txt)
(set-text-properties 0 (length txt) nil txt)
txt)
(defun print-line ()
(print (strip-text-properties
(thing-at-point 'line))
(get-buffer "*scratch*")))
I've tried some things but it's weird, I don't really understand how text properties work.
For example:
(type-of (thing-at-point 'line)) => string
As you've said if one tries to print it, the properties are printed as well, but if one tries to insert it:
(insert (format "%s" (thing-at-point 'line)))
Only the string is printed, not the properties.
So it seems to me that those properties are just bound to the string but you can manipulate the string as usual:
(lenght (thing-at-point 'line))
(substring (thing-at-point 'line) 0 2)
However, if all you want is the line, and the line only you can use buffer-substring-no-properties
:
(defun print-line ()
(print (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With