The buffer contains a mixture of text that is read-only (with 'read-only text properties) and read-write (i.e., no 'read-only text properties). I want to [up/down]case-region as to the read-write sections, but am unable to do so due to the 'read-only sections. How can I [up/down]case everything that is read-write within the defined BEG/END of the region, skipping the read-only text, and not yielding any error message?
Asked
Active
Viewed 38 times
1
lawlist
- 19,106
- 5
- 38
- 120
1 Answers
2
You could use this command:
(defun on-writeable-portions (fn beg end)
"Call FN on all writeable subregions of BEG - END."
(interactive "CCommand: \nr")
(when (get-text-property beg 'read-only)
(setq beg (next-single-property-change beg 'read-only nil (1+ end))))
(while (< beg end)
(let ((lim (next-single-property-change beg 'read-only nil (1+ end))))
(funcall fn beg (1- lim))
(setq beg
(if (< lim end)
(next-single-property-change lim 'read-only nil (1+ end))
end)))))
Omar
- 4,812
- 1
- 18
- 33
wdired-modebuffer with a variety of files containing absolute paths. The filename-non-directory is read-only along with the the file-attributes, but the base-file-name is read-write. The functionon-writeable-portionsskips the last letter of the base-file-name at the end of each line in the region. I don't know whether my workaround creates issues with other applications, but the workaround I chose was to change(1- lim)to justlim. With that change, it works as expected. – lawlist Feb 03 '21 at 01:05read-onlybegins anew; i.e., just before\nand just after the last character on the line (which in my case is the tail end of the base-file-name). I may decide to go ahead and modify thewdired-modecode to beginread-onlyat the beginning of the next line so that the\nhas no text properties, but I'll probably also keep the modification in the previous comment. You have been a big help and I've added your function to a couple of keyboard shortcuts inwdired-mode... – lawlist Feb 03 '21 at 01:16(1- lim)tolimto(min lim (point-max)), the latter of which avoids an args-out-of-range if the region extends to the end of the buffer ... – lawlist Feb 03 '21 at 01:38