emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Carsten Dominik <carsten.dominik@gmail.com>
To: Niels Giesen <niels.giesen@gmail.com>
Cc: Michael Brand <michael.ch.brand@gmail.com>,
	Org Mode <emacs-orgmode@gnu.org>
Subject: Re: understanding the function outline-level
Date: Thu, 9 Jun 2011 09:51:23 +0200	[thread overview]
Message-ID: <64F7F67C-4A1E-4DDB-B8F8-FCC6E8AB93B3@gmail.com> (raw)
In-Reply-To: <BANLkTinrHF7FUBSEqZ=HD0O0GiTXzrbYSA@mail.gmail.com>


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

  parent reply	other threads:[~2011-06-09  7:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2011-06-07 20:30 ` Aankhen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=64F7F67C-4A1E-4DDB-B8F8-FCC6E8AB93B3@gmail.com \
    --to=carsten.dominik@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=michael.ch.brand@gmail.com \
    --cc=niels.giesen@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).