How to use “hide-region” package in elisp

2019-08-29 03:57发布

问题:

There is this well-known package hide-region Link to the package (hide-region.el) I want to apply hide-region-hide from a certain "point a" to "point b" [a region] in my file. How can I do this? What I need to define? It works when I highlight manually some text, but I need to do it in my code and give it the beg. of a region and end of region and apply it to the resulted region.

回答1:

The package is somewhat poorly written, and does not allow you to pass it a region as arguments to the function. You can probably work around this by something like

(save-excursion
  (let (deactivate-mark) ; see save-excursion docs for why
    (set-mark point-a)  ; beginning of region you want to hide
    (goto-char point-b) ; end of region you want to hide
    (hide-region-hide) ) )

It would be better if hide-region-hide took the region as arguments when called noninteractively, though. Perhaps the maintainer would be happy to accept a patch for this. See also the documentation for set-mark which specifically advises against using it like I have done above. Furthermore, perhaps you also want to look at the documentation for save-excursion.



标签: elisp