I want to make the beginning of a line uneditable, which I can achieve by applying the read-only
and cursor-intangible
properties. But I have the problem, that line-beginning-position
moves point not to the first reachable position of the current line, as I expect, but to the end of the previous line. This may be a bug in Emacs. Is there some workaround for this issue?
Example: Let's say buffer contains "blablabla\nINTANGIBLEfooooo" INTANGIBLE has properties cursor-intangible t rear-nonsticky t front-sticky t. Then it is not possible to put point before any symbol of "INTANGIBLE", that is exactly wanted behavior, however if point is somewhere in fooooo, move-beginning-of-line puts point to the end of blablabla, which is strange.
Reconstruction:
- Copy and paste the following form into the
*scratch*
buffer. There the black rectangle ▮ indicates the point position. (You should not copy that character.)
(insert "\nblablabla\n"
(propertize "INTANGIBLE" 'cursor-intangible t 'rear-nonsticky t 'front-sticky t)
"fooooo")▮
- Eval the form with C-x C-e. You get
(insert "\nblablabla\n"
(propertize "INTANGIBLE" 'cursor-intangible t 'rear-nonsticky t 'front-sticky t)
"fooooo")
blablabla
INTANGIBLEfooooo▮
- Hit the home key. You end up with:
(insert "\nblablabla\n" (propertize "INTANGIBLE" 'cursor-intangible t 'rear-nonsticky t 'front-sticky t) "fooooo")
blablabla▮
INTANGIBLEfooooo
It becomes really interesting if one tries to get this behavior completely with the evaluation of a lisp expression:
(progn
(insert "\nblablabla\n"
(propertize "INTANGIBLE" 'cursor-intangible t 'rear-nonsticky t 'front-sticky t)
"fooooo")
(call-interactively #'move-beginning-of-line))▮
After evaluation with C-x C-e one gets:
I.e., point is between the last intangentiable character and the f
of foooooo
.
(progn (add-text-properties (point) (1+ (point)) '(read-only t cursor-intangible t)) (cursor-intangible-mode) (end-of-line) (beginning-of-line))
takes me back to where I started. Note that the functionline-beginning-position
which you mention does not move point.(progn (add-text-properties (1- (point)) (1+ (point)) '(read-only t cursor-intangible t)) (cursor-intangible-mode) (end-of-line) (beginning-of-line))
. Maybe something like that was the cause.cursor-intangible-mode
. Drew is right in that OP should provide more information about what they are trying to do and how.