emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* display outline headings up to certain level in search-view
@ 2012-12-14 17:46 Abdó Roig-Maranges
  2012-12-24 13:51 ` Bastien
  0 siblings, 1 reply; 2+ messages in thread
From: Abdó Roig-Maranges @ 2012-12-14 17:46 UTC (permalink / raw)
  To: emacs-orgmode

[-- 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-12-24 13:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-14 17:46 display outline headings up to certain level in search-view Abdó Roig-Maranges
2012-12-24 13:51 ` Bastien

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).