2

I know it's possible to make a "portion" of a buffer read-only. As an effect, the whole line becomes uneditable. What I would like it to make a specific region uneditable, for exemple a rectangle region :

- item n°1 (uneditable) : "editable part 1"
- item n°2 (uneditable) : "editable part 2"
- and so on.

I'm pretty sure it's something customizable but I'm not well acquainted with elisp yet. Thanks for your insights.

3
  • 2
    Possible duplicate of Sentence in text is read only even though the buffer is not, how to fix this?
    – phils
    Commented Oct 1, 2018 at 9:53
  • Sorry, I'm aware of this post but it doesn't help (it makes the whole line uneditable).
    – loukios
    Commented Oct 1, 2018 at 19:41
  • The linked set-region-read-only function does what it says -- it makes the region read-only. Use it on part of a line, and only that part of the line will be read-only.
    – phils
    Commented Oct 1, 2018 at 20:59

1 Answer 1

2

It sounds like you very specifically want this for rectangles, rather than for "specific regions".

You can combine https://emacs.stackexchange.com/a/10093/454 (which works on a region) with these rectangle commands:

(defun set-rectangle-read-only (begin end)
  "`set-region-read-only' on a rectangle."
  (interactive "r")
  (save-excursion
    (apply-on-rectangle
     (lambda (startcol endcol)
       (set-region-read-only
        (progn (move-to-column startcol) (point))
        (progn (move-to-column endcol) (point))))
     begin end)))

(defun set-rectangle-writeable (begin end)
  "`set-region-writeable' on a rectangle."
  (interactive "r")
  (save-excursion
    (apply-on-rectangle
     (lambda (startcol endcol)
       (set-region-writeable
        (progn (move-to-column startcol) (point))
        (progn (move-to-column endcol) (point))))
     begin end)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.