emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] v3, with support for narrowing


From: Nick Dokos
Subject: Re: [O] v3, with support for narrowing
Date: Thu, 28 Apr 2011 23:35:41 -0400

Eric Abrahamsen <address@hidden> wrote:

> On Fri, Apr 29 2011, Simon Guest wrote:
> 
> > At Thu, 28 Apr 2011 15:47:07 -0700,
> > Samuel Wales wrote:
> >> Is it possible to make it so that you can show the overlays for just a
> >> subtree or region instead of the entire buffer?
> >
> > Hi Samuel,
> >
> > Good idea!  So I just fixed it to handle narrowing properly, so narrow
> > to your region or subtree of interest first, and then count as usual.
> >
> > Attached v3 which does this.  I'm not normally this responsive, you
> > just caught me at a good time.  ;-)
> 
> Is this still a good time? Because what I'd really like is
> inclusion/exclusion tags, so that I can mark some subtrees to count, and
> others to ignore. I tried doing this last night, based on other parts of
> the export code, and my elisp failed. Perhaps just exclusion tags?
> Here's hoping you still have a bit of time/interest for improvements!
> 
> (I'm translating a novel, not writing one, and want to keep the original
> text out of the count. Plus I've got a bunch of research/notes sections
> that should be excluded.)
> 
> If you're out of time, I'll have another whack at it, and maybe bring my
> broken efforts to the list.
> 

The mapping API allows you to walk through the entries, filter the ones
you want and apply a function on each remaining entry. So cribbing heavily
from Simon's code, the following should count all the entries with tag "foo":

--8<---------------cut here---------------start------------->8---
(defun show-count ()
  (let ((p (point))
        wc)
    (when (setq wc (get-text-property p :org-wc))
      (org-wc-put-overlay wc (funcall outline-level)))
    (when org-remove-highlights-with-change
      (org-add-hook 'before-change-functions 'org-wc-remove-overlays
                    nil 'local))))

(defun count-foo ()
  (interactive)
  (let (bmp (buffer-modified-p))
    (org-wc-count-subtrees)
    (org-map-entries 'show-count "+foo" 'file)
    (set-buffer-modified-p bmp)))
--8<---------------cut here---------------end--------------->8---

Nick



reply via email to

[Prev in Thread] Current Thread [Next in Thread]