* Re: hideshow minor-mode [not found] <mailman.11001.1350265231.855.help-gnu-emacs@gnu.org> @ 2012-10-15 18:04 ` Michael Heerdegen 2012-10-15 23:30 ` Shiyuan [not found] ` <mailman.11078.1350343816.855.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 8+ messages in thread From: Michael Heerdegen @ 2012-10-15 18:04 UTC (permalink / raw) To: help-gnu-emacs Shiyuan <gshy2014@gmail.com> writes: > I want to turn-on the hide-show-minor-mode in a user-defined > mymode. But it gives me the error: mymode doesn't support hide show > minor mode. I have put (require 'hideshow) at the beginning of > mymode.el, and also > (hs-minor-mode 1) in the body of the definition of the major mode, and > after that > I put (add-to-list 'hs-special-modes-alist '(mymode "{" "}" "/[*/]" > nil nil)) in mymode.el. > > What else I should do to utilize the hs-minor-mode in mymode? Thanks. Enabling `hs-minor-mode' tests if `comment-start' and `comment-end' are bound to something non-nil and fails otherwise. This happens even before `hs-special-modes-alist' is handled. IMHO this doesn't make much sense. FWIW, your minor-mode must bind `comment-start' and `comment-end'. If your mode doesn't have comments at all, you can bind these to a regexp that always fails matching - like "\\=[^[:ascii:][:nonascii:]]". Does that help? Michael. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: hideshow minor-mode 2012-10-15 18:04 ` hideshow minor-mode Michael Heerdegen @ 2012-10-15 23:30 ` Shiyuan [not found] ` <mailman.11078.1350343816.855.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 8+ messages in thread From: Shiyuan @ 2012-10-15 23:30 UTC (permalink / raw) To: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 1707 bytes --] Yes, that solves the problem. Now, I can turn on hs-minor-mode. But actually the block in my major mode is defined by tags, not by braces/parentheses, like, [begin] This is the block. This is the block. [end] accord to the commentary in the hideshow.el file, we can define the BEGIN and the END of the block by regex, this is what I did, (add-to-list 'hs-special-modes-alist '(mymode "\\[begin]" "\\[end]" "#" nil nil)) However, it doesn't work. Anything else I need to do? or is there other packages allow me to fold the source where the blocks are defined in this way? Thanks. Shiyuan On Mon, Oct 15, 2012 at 1:04 PM, Michael Heerdegen <michael_heerdegen@web.de > wrote: > Shiyuan <gshy2014@gmail.com> writes: > > > I want to turn-on the hide-show-minor-mode in a user-defined > > mymode. But it gives me the error: mymode doesn't support hide show > > minor mode. I have put (require 'hideshow) at the beginning of > > mymode.el, and also > > (hs-minor-mode 1) in the body of the definition of the major mode, and > > after that > > I put (add-to-list 'hs-special-modes-alist '(mymode "{" "}" "/[*/]" > > nil nil)) in mymode.el. > > > > What else I should do to utilize the hs-minor-mode in mymode? Thanks. > > Enabling `hs-minor-mode' tests if `comment-start' and `comment-end' are > bound to something non-nil and fails otherwise. This happens even > before `hs-special-modes-alist' is handled. IMHO this doesn't make much > sense. FWIW, your minor-mode must bind `comment-start' and > `comment-end'. > > If your mode doesn't have comments at all, you can bind these to a > regexp that always fails matching - like "\\=[^[:ascii:][:nonascii:]]". > > Does that help? > > > Michael. > > [-- Attachment #2: Type: text/html, Size: 2521 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <mailman.11078.1350343816.855.help-gnu-emacs@gnu.org>]
* Re: hideshow minor-mode [not found] ` <mailman.11078.1350343816.855.help-gnu-emacs@gnu.org> @ 2012-10-16 1:03 ` Michael Heerdegen 2012-10-16 4:20 ` Shiyuan [not found] ` <mailman.11086.1350361261.855.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 8+ messages in thread From: Michael Heerdegen @ 2012-10-16 1:03 UTC (permalink / raw) To: help-gnu-emacs Shiyuan <gshy2014@gmail.com> writes: > Yes, that solves the problem. Now, I can turn on hs-minor-mode. > > But actually the block in my major mode is defined by tags, not by > braces/parentheses, like, > [begin] > This is the block. > This is the block. > [end] > > accord to the commentary in the hideshow.el file, we can define the > BEGIN and the END of the block by regex, this is what I did, > > (add-to-list 'hs-special-modes-alist '(mymode "\\[begin]" "\\[end]" > "#" nil nil)) Yes, that's not wrong. > However, it doesn't work. Anything else I need to do? I'm afraid you'll need to specify a FORWARD-SEXP-FUNC element in your `hs-special-modes-alist' entry, since the default `forward-sexp' function won't work for your mode. This function must accept one argument ARG and implement moving over ARG balanced blocks. If you don't have something like that yet - I tried the following: --8<---------------cut here---------------start------------->8--- (defun mymode-forward-sexp-func (arg) (dotimes (_ arg) (let ((counter 0)) (catch 'done (while t (search-forward-regexp "\\[begin]\\|\\[end]") (setq counter (+ counter (if (looking-back "\\[begin]") 1 -1))) (when (= counter 0) (throw 'done t))))))) --8<---------------cut here---------------end--------------->8--- It doesn't check for comments, dunno what else I forgot. But, if I then use (add-to-list 'hs-special-modes-alist '(mymode "\\[begin]" "\\[end]" "#" my-mode-forward-sexp-func)) folding worked for me in a test buffer using your syntax. > or is there other packages allow me to fold the source where the > blocks are defined in this way? Fundamentally, hideshow is fine for that. It's just the setup that isn't trivial. No doubt, there is room for improvement. Regards, Michael. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: hideshow minor-mode 2012-10-16 1:03 ` Michael Heerdegen @ 2012-10-16 4:20 ` Shiyuan [not found] ` <mailman.11086.1350361261.855.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 8+ messages in thread From: Shiyuan @ 2012-10-16 4:20 UTC (permalink / raw) To: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 2187 bytes --] Michael, Thanks for the detailed reply. However, it doesn't work for me. I guess I make a mistake somewhere. Here is mymode.el: http://paste.lisp.org/display/132611 Thanks. On Mon, Oct 15, 2012 at 8:03 PM, Michael Heerdegen <michael_heerdegen@web.de > wrote: > Shiyuan <gshy2014@gmail.com> writes: > > > Yes, that solves the problem. Now, I can turn on hs-minor-mode. > > > > But actually the block in my major mode is defined by tags, not by > > braces/parentheses, like, > > [begin] > > This is the block. > > This is the block. > > [end] > > > > accord to the commentary in the hideshow.el file, we can define the > > BEGIN and the END of the block by regex, this is what I did, > > > > (add-to-list 'hs-special-modes-alist '(mymode "\\[begin]" "\\[end]" > > "#" nil nil)) > > Yes, that's not wrong. > > > However, it doesn't work. Anything else I need to do? > > I'm afraid you'll need to specify a FORWARD-SEXP-FUNC element in your > `hs-special-modes-alist' entry, since the default `forward-sexp' > function won't work for your mode. > > This function must accept one argument ARG and implement moving over ARG > balanced blocks. > > If you don't have something like that yet - I tried the following: > > --8<---------------cut here---------------start------------->8--- > (defun mymode-forward-sexp-func (arg) > (dotimes (_ arg) > (let ((counter 0)) > (catch 'done > (while t > (search-forward-regexp "\\[begin]\\|\\[end]") > (setq counter (+ counter (if (looking-back "\\[begin]") 1 -1))) > (when (= counter 0) (throw 'done t))))))) > --8<---------------cut here---------------end--------------->8--- > > It doesn't check for comments, dunno what else I forgot. But, > if I then use > > (add-to-list 'hs-special-modes-alist '(mymode "\\[begin]" "\\[end]" > "#" my-mode-forward-sexp-func)) > > folding worked for me in a test buffer using your syntax. > > > or is there other packages allow me to fold the source where the > > blocks are defined in this way? > > Fundamentally, hideshow is fine for that. It's just the setup that > isn't trivial. No doubt, there is room for improvement. > > > Regards, > > Michael. > > > [-- Attachment #2: Type: text/html, Size: 3100 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <mailman.11086.1350361261.855.help-gnu-emacs@gnu.org>]
* Re: hideshow minor-mode [not found] ` <mailman.11086.1350361261.855.help-gnu-emacs@gnu.org> @ 2012-10-16 5:17 ` Michael Heerdegen 2012-10-16 14:40 ` Shiyuan [not found] ` <mailman.11111.1350398455.855.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 8+ messages in thread From: Michael Heerdegen @ 2012-10-16 5:17 UTC (permalink / raw) To: help-gnu-emacs Hi again, > Michael, > Thanks for the detailed reply. However, it doesn't work for me. I > guess I make a mistake somewhere. Here is mymode.el: > > http://paste.lisp.org/display/132611 Yes, there are two little errors. First, you register your mode in `hs-special-modes-alist' after you enable hs-minor-mode. That's too late, because hideshow then has already initialized its stuff. Also, adding to `hs-special-modes-alist' has to be done only once, and not every time mymode is enabled. Second, you quoted mymode-forward-sexp-func in your quoted list: | '(mymode "\\[begin]" "\\[end]" "#" 'mymode-forward-sexp-func nil)) ^ That's not needed, remember, the quote before a list already prevents evaluation of its members (you want to specify a symbol). So, this should do the trick: --8<---------------cut here---------------start------------->8--- (require 'hideshow) (defun mymode-forward-sexp-func (arg) "move over ARG balanced blocks; This is needed by hs-minor-mode" (dotimes (number arg) (let ((counter 0)) (catch 'done (while t (search-forward-regexp "\\[begin]\\|\\[end]") (setq counter (+ counter (if (looking-back "\\[begin]") 1 -1))) (when (= counter 0) (throw 'done t))))))) (add-to-list 'hs-special-modes-alist '(mymode "\\[begin]" "\\[end]" "#" mymode-forward-sexp-func)) (define-derived-mode mymode fundamental-mode "mymode is a major mode for fun." (setq mode-name "mymode") (setq comment-start "#") (setq comment-end "") (hs-minor-mode 1)) --8<---------------cut here---------------end--------------->8--- Of course, that's all just for playing. If mymode was a major-mode really to be used, you would leave it up to the user to call `hs-minor-mode' e.g. in `mymode-hook', and not call it in the mode definition. Michael. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: hideshow minor-mode 2012-10-16 5:17 ` Michael Heerdegen @ 2012-10-16 14:40 ` Shiyuan [not found] ` <mailman.11111.1350398455.855.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 8+ messages in thread From: Shiyuan @ 2012-10-16 14:40 UTC (permalink / raw) To: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 2137 bytes --] Michael, That works. Thank you very much for guiding me into the world of Lisp. Shiyuan On Tue, Oct 16, 2012 at 12:17 AM, Michael Heerdegen < michael_heerdegen@web.de> wrote: > Hi again, > > > Michael, > > Thanks for the detailed reply. However, it doesn't work for me. I > > guess I make a mistake somewhere. Here is mymode.el: > > > > http://paste.lisp.org/display/132611 > > Yes, there are two little errors. > > First, you register your mode in `hs-special-modes-alist' after you > enable hs-minor-mode. That's too late, because hideshow then has > already initialized its stuff. Also, adding to `hs-special-modes-alist' > has to be done only once, and not every time mymode is enabled. > > Second, you quoted mymode-forward-sexp-func in your quoted list: > > | '(mymode "\\[begin]" "\\[end]" "#" 'mymode-forward-sexp-func nil)) > ^ > > That's not needed, remember, the quote before a list already prevents > evaluation of its members (you want to specify a symbol). > > So, this should do the trick: > > --8<---------------cut here---------------start------------->8--- > (require 'hideshow) > > (defun mymode-forward-sexp-func (arg) > "move over ARG balanced blocks; This is needed by hs-minor-mode" > (dotimes (number arg) > (let ((counter 0)) > (catch 'done > (while t > (search-forward-regexp "\\[begin]\\|\\[end]") > (setq counter (+ counter (if (looking-back "\\[begin]") 1 -1))) > (when (= counter 0) (throw 'done t))))))) > > (add-to-list 'hs-special-modes-alist '(mymode "\\[begin]" "\\[end]" "#" > mymode-forward-sexp-func)) > > (define-derived-mode mymode fundamental-mode > "mymode is a major mode for fun." > (setq mode-name "mymode") > (setq comment-start "#") > (setq comment-end "") > (hs-minor-mode 1)) > --8<---------------cut here---------------end--------------->8--- > > Of course, that's all just for playing. If mymode was a major-mode > really to be used, you would leave it up to the user to call > `hs-minor-mode' e.g. in `mymode-hook', and not call it in the mode > definition. > > > Michael. > > [-- Attachment #2: Type: text/html, Size: 2990 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <mailman.11111.1350398455.855.help-gnu-emacs@gnu.org>]
* Re: hideshow minor-mode [not found] ` <mailman.11111.1350398455.855.help-gnu-emacs@gnu.org> @ 2012-10-16 18:09 ` Michael Heerdegen 0 siblings, 0 replies; 8+ messages in thread From: Michael Heerdegen @ 2012-10-16 18:09 UTC (permalink / raw) To: help-gnu-emacs Shiyuan <gshy2014@gmail.com> writes: > That works. Fine. Maybe also have a look at folding.el, if you don't yet know it: http://www.emacswiki.org/emacs/FoldingMode It uses explicit markers, but therefore works out of the box in any mode. Regards, Michael. > Shiyuan > > On Tue, Oct 16, 2012 at 12:17 AM, Michael Heerdegen <michael_heerdegen@web.de> wrote: > > Hi again, > > > > Michael, > > Thanks for the detailed reply. However, it doesn't work for me. I > > guess I make a mistake somewhere. Here is mymode.el: > > > > http://paste.lisp.org/display/132611 > > > Yes, there are two little errors. > > First, you register your mode in `hs-special-modes-alist' after you > enable hs-minor-mode. That's too late, because hideshow then has > already initialized its stuff. Also, adding to `hs-special-modes-alist' > has to be done only once, and not every time mymode is enabled. > > Second, you quoted mymode-forward-sexp-func in your quoted list: > > | '(mymode "\\[begin]" "\\[end]" "#" 'mymode-forward-sexp-func nil)) > ^ > > That's not needed, remember, the quote before a list already prevents > evaluation of its members (you want to specify a symbol). > > So, this should do the trick: > > --8<---------------cut here---------------start------------->8--- > (require 'hideshow) > > (defun mymode-forward-sexp-func (arg) > "move over ARG balanced blocks; This is needed by hs-minor-mode" > (dotimes (number arg) > > (let ((counter 0)) > (catch 'done > (while t > (search-forward-regexp "\\[begin]\\|\\[end]") > (setq counter (+ counter (if (looking-back "\\[begin]") 1 -1))) > (when (= counter 0) (throw 'done t))))))) > > > (add-to-list 'hs-special-modes-alist '(mymode "\\[begin]" "\\[end]" "#" mymode-forward-sexp-func)) > > (define-derived-mode mymode fundamental-mode > "mymode is a major mode for fun." > (setq mode-name "mymode") > (setq comment-start "#") > (setq comment-end "") > (hs-minor-mode 1)) > --8<---------------cut here---------------end--------------->8--- > > Of course, that's all just for playing. If mymode was a major-mode > really to be used, you would leave it up to the user to call > `hs-minor-mode' e.g. in `mymode-hook', and not call it in the mode > definition. > > > Michael. > ^ permalink raw reply [flat|nested] 8+ messages in thread
* hideshow minor-mode @ 2012-10-15 1:40 Shiyuan 0 siblings, 0 replies; 8+ messages in thread From: Shiyuan @ 2012-10-15 1:40 UTC (permalink / raw) To: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 465 bytes --] Hi, I want to turn-on the hide-show-minor-mode in a user-defined mymode. But it gives me the error: mymode doesn't support hide show minor mode. I have put (require 'hideshow) at the beginning of mymode.el, and also (hs-minor-mode 1) in the body of the definition of the major mode, and after that I put (add-to-list 'hs-special-modes-alist '(mymode "{" "}" "/[*/]" nil nil)) in mymode.el. What else I should do to utilize the hs-minor-mode in mymode? Thanks. [-- Attachment #2: Type: text/html, Size: 605 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-10-16 18:09 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <mailman.11001.1350265231.855.help-gnu-emacs@gnu.org> 2012-10-15 18:04 ` hideshow minor-mode Michael Heerdegen 2012-10-15 23:30 ` Shiyuan [not found] ` <mailman.11078.1350343816.855.help-gnu-emacs@gnu.org> 2012-10-16 1:03 ` Michael Heerdegen 2012-10-16 4:20 ` Shiyuan [not found] ` <mailman.11086.1350361261.855.help-gnu-emacs@gnu.org> 2012-10-16 5:17 ` Michael Heerdegen 2012-10-16 14:40 ` Shiyuan [not found] ` <mailman.11111.1350398455.855.help-gnu-emacs@gnu.org> 2012-10-16 18:09 ` Michael Heerdegen 2012-10-15 1:40 Shiyuan
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.