emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Abdó Roig-Maranges" <abdo.roig@gmail.com>
To: emacs-orgmode@gnu.org
Subject: display outline headings up to certain level in search-view
Date: Fri, 14 Dec 2012 18:46:11 +0100	[thread overview]
Message-ID: <87mwxgplwc.fsf@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 544 bytes --]


Hi,

Let's say I have an org file structured like this

* Project 1
** Tasks
   foo
** Ideas

* Project 2
** Tasks
   bar

When I search 'foo' I'd like the agenda search-view to display 'Project
1' instead of the closer, but less informative 'Tasks'

The attached patch solves this by adding a configuration parameter that
sets the maximum outline level for the headings displayed in the results
of a search-view. This way, I can have a custom search on the above org
file with org-agenda-search-view-max-outline-level set to 1.

Abdó Roig.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-patch, Size: 2148 bytes --]

From 830acc3fe6e7235618df080f7b6878234cb831c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Abd=C3=B3=20Roig-Maranges?= <abdo.roig@gmail.com>
Date: Wed, 12 Dec 2012 20:52:40 +0100
Subject: [PATCH] set max level to display in search-view results

* lisp/org-agenda.el (org-search-view) Adds the config setting
  org-agenda-search-view-max-outline-level that limits the depth of
  items on an agenda-search-view results. When a match is found,
  displays the innermost outline heading containing the match such
  that its level does not exceed
  org-agenda-search-view-max-outline-level.
---
 lisp/org-agenda.el | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 5343887..0b85b9c 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -1320,6 +1320,12 @@ When nil, they may also match part of a word."
   :version "24.1"
   :type 'boolean)
 
+(defcustom org-agenda-search-view-max-outline-level nil
+  "Maximum outline level to display in search view."
+  :group 'org-agenda-search-view
+  :version "24.3"
+  :type 'integer)
+
 (defgroup org-agenda-time-grid nil
   "Options concerning the time grid in the Org-mode Agenda."
   :tag "Org Agenda Time Grid"
@@ -4397,10 +4403,22 @@ in `org-agenda-text-search-extra-files'."
 		    (goto-char (max (point-min) (1- (point))))
 		    (while (re-search-forward regexp nil t)
 		      (org-back-to-heading t)
+		      (while (and org-agenda-search-view-max-outline-level
+			(> (org-reduced-level (org-outline-level)) org-agenda-search-view-max-outline-level)
+			(forward-line -1)
+			(outline-back-to-heading t)))
+
 		      (skip-chars-forward "* ")
 		      (setq beg (point-at-bol)
 			    beg1 (point)
-			    end (progn (outline-next-heading) (point)))
+			    end (progn
+			      (outline-next-heading)
+			      (while (and org-agenda-search-view-max-outline-level
+			        (> (org-reduced-level (org-outline-level)) org-agenda-search-view-max-outline-level)
+				(forward-line 1)
+				(outline-next-heading)))
+			      (point)))
+
 		      (catch :skip
 			(goto-char beg)
 			(org-agenda-skip)
-- 
1.8.0.2


             reply	other threads:[~2012-12-14 17:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-14 17:46 Abdó Roig-Maranges [this message]
2012-12-24 13:51 ` display outline headings up to certain level in search-view Bastien

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=87mwxgplwc.fsf@gmail.com \
    --to=abdo.roig@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /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).