Ravindra Viswanath writes:
When using selective display (hidden lines), is it possible to leave
the
hidden lines unchanged when making edits - for example find/replace,
string/cut rectangle, etc - changing only the visible lines, instead ?
That would depend on the hidden-lines mode (which I don't currently
have installed so I can't check it). You could add code to make the
hidden lines read-only, but that would prevent changes by causing an
error when using find/replace or rectangle operations. It is easy to
write one function
(defun hidden-lines-replace-string (from-string to-string &optional delimited)
(interactive "sFind: \nsReplacement: \nP")
(setq from-string (regexp-quote from-string))
(when delimited
(setq from-string (concat "\\b" from-string "\\b")))
;; Stop worrying about the "re-".
;; This is plenty efficient for interactive use.
(while (re-search-forward from-string nil t)
(condition-case nil
(replace-match to-string)
(extent-read-only (goto-char (match-end 0))))))
but I imagine there are several such functions you need. It would be
possible to write a macro based on this pattern:
(defmacro with-skipping-read-only-extents (self args &rest body)
;; SELF must be the name of the iterative function being defined.
;; ARGS is its argument list.
;; BODY is the implementation.
`(condition-case nil
(progn ,@body)
(extent-read-only (goto-char (match-end 0))
(apply self args))))
but it might not be very useful. I don't even know if
(defun hidden-lines-replace-string (from-string to-string &optional delimited)
(with-skipping-read-only-extents
hidden-lines-replace-string (from-string to-string &optional delimited)
(replace-string from-string to-string delimited)))
would work correctly (replace-string may take care to save the
match-data, in which case you won't have access to the needed
information about the match that found read-only data), and I suspect
(defun hidden-lines-kill-rectangle (start end &optional fill)
(with-skipping-read-only-extents
hidden-lines-kill-rectangle (start end &optional fill)
(kill-rectangle start end fill)))
would have rather surprising behavior. Also, this strategy based on
handling the error would not work for *copying* since that doesn't try
to change the read-only text.
There is a library called atomic-extents which adds a property called
'atomic that prevents point from entering an atomic extent. However,
apparently it doesn't work very well. Certain functions such as
delete-backward-char don't respect it (see C-h f set-extent-property),
and I suspect that anything written in C (such as the find/replace
functions) would suffer from this. Also functions that operate on the
whole region (eg, copying it) will continue to do so; by design atomic
extents don't prevent access to the extent, they just require that it
be treated as a whole or not at all.
GNU Emacs has an 'intangible property that can be applied to text, but
I seem to recall that they don't use it much, so people who try to use
it often find it doesn't meet their needs. In your case, it might
work for find/replace, but not for copying. Or vice versa, I don't
know much more than the name and that it is more or less similar to
atomic extents.
Bottom line, I suspect you're going to have to write a lot of code
yourself to make this work naturally, because none of the primitives
are designed to skip hidden text. There's no question that it can be
done, just is it worth it to you.
_______________________________________________
XEmacs-Beta mailing list
XEmacs-Beta(a)xemacs.org
http://lists.xemacs.org/mailman/listinfo/xemacs-beta