Web lists-archives.com

Re: text editors




mick crane [2019-03-25 04:38:31Z] wrote:

> Is there any text editor, preferably in a terminal that has the facility
> to protect lines in the document, not the document itself ?
> I've got 2 blocks of "code" that look similar and I keep editing the
> wrong one and then it doesn't work.

GNU Emacs has text properties which can be added to any piece of text.
One of the properties is named "read-only". I made two functions to
handle the situation you described.

Put these function to you Emacs's init file (~/.emacs or
~/.emacs.d/init.el):


    (defun read-only-region (beg end)
      "Makes a region in the current buffer read only, from buffer
    position BEG to END. If this function is called interactively use
    the current hightlighted region."
      (interactive "r")
      (add-text-properties beg end '(read-only t)))

    (defun remove-read-only ()
      "Remove all read only text properties from the current buffer."
      (interactive)
      (let ((inhibit-read-only t))
        (remove-text-properties (point-min) (point-max)
                                '(read-only t))))


Select some text in a buffer and execute command "Alt+x
read-only-region". That area becomes read only. To remove all read only
text areas from the current buffer execute command "Alt+x
remove-read-only".

-- 
/// Teemu Likonen   - .-..   <https://keybase.io/tlikonen> //
// PGP: 4E10 55DC 84E9 DFF6 13D7 8557 719D 69D3 2453 9450 ///

Attachment: signature.asc
Description: PGP signature