* understanding the function outline-level @ 2011-06-07 16:23 Michael Brand 2011-06-07 17:54 ` Jambunathan K ` (2 more replies) 0 siblings, 3 replies; 6+ messages in thread From: Michael Brand @ 2011-06-07 16:23 UTC (permalink / raw) To: Org Mode Hi all I am on the way of tracking down an (Org?) buglet and now outline-level tries to strike me with my lack of experience with "Match Data" of Emacs search and I would like to ask for some help to understand. M-: (outline-level) returns a value that I don't understand yet. The number does not correspond to the amount of stars and is independent of at the beginning of which line the point was before. And when I look at the implementation of outline-level I am missing a function that initializes the "Match Data". Where is that last search or match operation? Michael ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: understanding the function outline-level 2011-06-07 16:23 understanding the function outline-level Michael Brand @ 2011-06-07 17:54 ` Jambunathan K 2011-06-07 18:33 ` Niels Giesen 2011-06-07 20:30 ` Aankhen 2 siblings, 0 replies; 6+ messages in thread From: Jambunathan K @ 2011-06-07 17:54 UTC (permalink / raw) To: Michael Brand; +Cc: Org Mode Michael Brand <michael.ch.brand@gmail.com> writes: > Hi all > > I am on the way of tracking down an (Org?) buglet and now > outline-level tries to strike me with my lack of experience with > "Match Data" of Emacs search and I would like to ask for some help to > understand. > > M-: (outline-level) returns a value that I don't understand yet. The > number does not correspond to the amount of stars and is independent > of at the beginning of which line the point was before. And when I > look at the implementation of outline-level I am missing a function > that initializes the "Match Data". Where is that last search or match > operation? (A quick hint. May not be complete though) The typical call sequence seems to be: 1. Move the cursor to a headline. 2. Call outline-level. It is (1) which presumably does a regexp search and ends up in the headline. So outline-level cannot be called in and of itself. It always need to be preceded by some other call which positions the cursor in a headline in the first place. Cursory look suggests that there are multiple ways by which (1) could be achieved - mostly they seem to be outline tree traversal functions. Summary: Look at outline-level in source code. Jump a few lines above and watch out for any sort of traversal functions. ,----[ C-h f outline-level RET ] | outline-level is a compiled Lisp function in `outline.el'. | | (outline-level) | | Return the depth to which a statement is nested in the outline. | Point must be at the beginning of a header line. | This is actually either the level specified in `outline-heading-alist' | or else the number of characters matched by `outline-regexp'. | | [back] `---- > > Michael > > -- ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: understanding the function outline-level 2011-06-07 16:23 understanding the function outline-level Michael Brand 2011-06-07 17:54 ` Jambunathan K @ 2011-06-07 18:33 ` Niels Giesen 2011-06-09 7:04 ` Michael Brand 2011-06-09 7:51 ` Carsten Dominik 2011-06-07 20:30 ` Aankhen 2 siblings, 2 replies; 6+ messages in thread From: Niels Giesen @ 2011-06-07 18:33 UTC (permalink / raw) To: Michael Brand; +Cc: Org Mode Hi Michael, match data get set by searches. One can inhibit match-data being cluttered by using the `save-match-data' macro (you should probably do so when using searches in a lisp program). Outline.el seems to make very frequent use of this 'global' data; instead of passing this data on via function arguments or so, it depends on this dynamically set data, which makes it very hard to see who does what. Some prodding about led me to believe the searching in `outline-back-to-heading' is your suspect (but I have not investigated this further). At least (progn (outline-back-to-heading) (outline-level)) Returns a reasonable answer each time I run it. (info "(Elisp)Match Data") May be of interest to you. On Tue, Jun 7, 2011 at 6:23 PM, Michael Brand <michael.ch.brand@gmail.com> wrote: > Hi all > > I am on the way of tracking down an (Org?) buglet and now > outline-level tries to strike me with my lack of experience with > "Match Data" of Emacs search and I would like to ask for some help to > understand. > > M-: (outline-level) returns a value that I don't understand yet. The > number does not correspond to the amount of stars and is independent > of at the beginning of which line the point was before. And when I > look at the implementation of outline-level I am missing a function > that initializes the "Match Data". Where is that last search or match > operation? > > Michael > > -- http://pft.github.com ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: understanding the function outline-level 2011-06-07 18:33 ` Niels Giesen @ 2011-06-09 7:04 ` Michael Brand 2011-06-09 7:51 ` Carsten Dominik 1 sibling, 0 replies; 6+ messages in thread From: Michael Brand @ 2011-06-09 7:04 UTC (permalink / raw) To: Niels Giesen; +Cc: Org Mode On Tue, Jun 7, 2011 at 20:33, Niels Giesen <niels.giesen@gmail.com> wrote: > Some prodding about led me to believe the searching in > `outline-back-to-heading' is your suspect (but I have not investigated > this further). At least > > (progn > (outline-back-to-heading) > (outline-level)) > > Returns a reasonable answer each time I run it. Aha, yes this is what I was missing. I thought that o*-back-to-heading is only to ensure that point is at the right place and that this could be emulated by manually moving point, before calling outline-level. Now I understand that there is more. Thank you all for the explanations. With this help I was able to track down the buglet for which I will send a patch in a moment. Michael ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: understanding the function outline-level 2011-06-07 18:33 ` Niels Giesen 2011-06-09 7:04 ` Michael Brand @ 2011-06-09 7:51 ` Carsten Dominik 1 sibling, 0 replies; 6+ messages in thread From: Carsten Dominik @ 2011-06-09 7:51 UTC (permalink / raw) To: Niels Giesen; +Cc: Michael Brand, Org Mode On Jun 7, 2011, at 8:33 PM, Niels Giesen wrote: > Hi Michael, > > match data get set by searches. One can inhibit match-data being > cluttered by using the `save-match-data' macro (you should probably do > so when using searches in a lisp program). > > Outline.el seems to make very frequent use of this 'global' data; > instead of passing this data on via function arguments or so, it > depends on this dynamically set data, which makes it very hard to see > who does what. > > Some prodding about led me to believe the searching in > `outline-back-to-heading' is your suspect (but I have not investigated > this further). At least > > (progn > (outline-back-to-heading) > (outline-level)) Or, alternatively, if you are already at the beginning of the headline (and (looking-at outline-regexp) (funcall 'outline-level)) So outline-level needs to just have matched when calling that function. IMPORTANT: Using (funcall 'outline-level) is more general as major modes are allowed to set their own function for level calculation. In fact, calling (outline-level) in Org-mode will give the wrong result, because the regexp also matches the space character after the stars, so the level is one less than the length of the match string. - Carsten > > Returns a reasonable answer each time I run it. > > (info "(Elisp)Match Data") > > May be of interest to you. > > On Tue, Jun 7, 2011 at 6:23 PM, Michael Brand > <michael.ch.brand@gmail.com> wrote: >> Hi all >> >> I am on the way of tracking down an (Org?) buglet and now >> outline-level tries to strike me with my lack of experience with >> "Match Data" of Emacs search and I would like to ask for some help to >> understand. >> >> M-: (outline-level) returns a value that I don't understand yet. The >> number does not correspond to the amount of stars and is independent >> of at the beginning of which line the point was before. And when I >> look at the implementation of outline-level I am missing a function >> that initializes the "Match Data". Where is that last search or match >> operation? >> >> Michael >> >> > > > > -- > http://pft.github.com > - Carsten ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: understanding the function outline-level 2011-06-07 16:23 understanding the function outline-level Michael Brand 2011-06-07 17:54 ` Jambunathan K 2011-06-07 18:33 ` Niels Giesen @ 2011-06-07 20:30 ` Aankhen 2 siblings, 0 replies; 6+ messages in thread From: Aankhen @ 2011-06-07 20:30 UTC (permalink / raw) To: Michael Brand, Org mailing list Hi Michael, On Tue, Jun 7, 2011 at 21:53, Michael Brand <michael.ch.brand@gmail.com> wrote: > I am on the way of tracking down an (Org?) buglet and now > outline-level tries to strike me with my lack of experience with > "Match Data" of Emacs search and I would like to ask for some help to > understand. > > M-: (outline-level) returns a value that I don't understand yet. The > number does not correspond to the amount of stars and is independent > of at the beginning of which line the point was before. And when I > look at the implementation of outline-level I am missing a function > that initializes the "Match Data". Where is that last search or match > operation? Here’s a slightly more complicated alternative method: ,---- | (progn | (org-back-to-heading) | (org-reduced-level (org-current-level))) `---- This will take into account `org-odd-levels-only'. Aankhen ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-06-09 7:51 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-06-07 16:23 understanding the function outline-level Michael Brand 2011-06-07 17:54 ` Jambunathan K 2011-06-07 18:33 ` Niels Giesen 2011-06-09 7:04 ` Michael Brand 2011-06-09 7:51 ` Carsten Dominik 2011-06-07 20:30 ` Aankhen
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).