How to use “hide-region” package in elisp

2019-08-29 03:46发布

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.

标签: elisp
1条回答
地球回转人心会变
2楼-- · 2019-08-29 04:19

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.

查看更多
登录 后发表回答