Re: [O] A simple way to search only headlines

2013-06-11 Thread Thorsten Jolitz
Suvayu Ali fatkasuvayu+li...@gmail.com writes:

 I wonder if semantic search can be leveraged to achieve the same.  It
 might open other possibilities: searching only links, list items, source
 blocks, ...  I think you get the point.  :-p

navi-mode.el works for Org-mode buffers too, e.g. using 

,-
| worg/org-contrib/babel/intro.org
`-

as an sufficiently complex example file, the following simple
keybindings yield the following search results in the *Navi* buffer:

command (show headlines up to level 2):
,--
| 2
`--

result:
,--
| 28 matches for ^\*\*?  in buffer: intro.org
|  14:* Improving this document  :noexport:
|  15:** DONE Document slice indexing of tables
|  16:** DONE Document synonymous alternatives
|  18:** DONE Describe useful functions
|  22:** DONE Language support
|  27:** DONE Document noweb references
|  29:** TODO Developments
|  55:** DONE Useful variables
|  57:** TODO Language specific header arguments
| 127:** DONE What function is bound to C-c '?
| 129:* Introduction
| 153:* Overview
| 179:* Initial Configuration
| 203:* Code Blocks
| 208:** Code Blocks in Org
| 241:** Code Blocks in Babel
| 268:* Source Code Execution
| 360:** Capturing the Results of Code Evaluation
| 429:** Session-based Evaluation
| 453:** Arguments to Code Blocks
| 539:** In-line Code Blocks
| 546:** Code Block Body Expansion
| 593:** A Meta-programming Language for Org-mode
| 652:* Using Code Blocks in Org Tables
| 842:* The Library of Babel
| 886:* Literate Programming
|1098:* Reproducible Research
|1136:* Footnotes
`--

command (show source-code blocks):
,--
| b
`--

result:

,---
| 30 matches for [long regexp] in buffer:intro.org
| 
|  93:#+begin_src python :file outfile.txt
| 225:#+begin_src org
| 234:#+begin_src org
| 249:#+begin_src org
| 289:#+begin_src ruby
| 304:#+begin_src sh
| 322:#+begin_src R :colnames yes
| 346:#+begin_src ditaa :file blue.png :cmdline -r
| 385:#+begin_src python :results value
| 414:#+begin_src python :results output
| 469:#+begin_src python
| 512:#+begin_src emacs-lisp
| 579:#+begin_src emacs-lisp :rownames yes :var data=user-data
| 585:#+begin_src emacs-lisp
| 647:#+begin_src R :session R-pie-example :file ../../images/babel/dirs.png
| 696:#+begin_src R 
| 776:#+begin_src emacs-lisp
| 788:#+begin_src sh :results silent
| 800:#+begin_src sh :results silent
| 812:#+begin_src ruby :results silent
| 824:#+begin_src python :results silent
| 837:#+begin_src R :results silent
| 878:  #+begin_src emacs-lisp 
| 950:#+begin_src sh :exports none
| 962:#+begin_src sh :exports none
| 983:#+begin_src sh :tangle hello.sh :exports none :noweb yes
| 994:#+begin_src sh 
|1051:   #+begin_src sh 
|1056:   #+begin_src sh
|1065:   #+begin_src emacs-lisp 
`---

command (show headlines up to level 2 and source-code blocks):

,--
| C-2 b
`--

result:

,---
| 58 matches for [long regexp] in buffer:intro.org
| 
|  14:* Improving this document  :noexport:
|  15:** DONE Document slice indexing of tables
|  16:** DONE Document synonymous alternatives
|  18:** DONE Describe useful functions
|  22:** DONE Language support
|  27:** DONE Document noweb references
|  29:** TODO Developments
|  55:** DONE Useful variables
|  57:** TODO Language specific header arguments
|  93:#+begin_src python :file outfile.txt
| 127:** DONE What function is bound to C-c '?
| 129:* Introduction
| 153:* Overview
| 179:* Initial Configuration
| 203:* Code Blocks
| 208:** Code Blocks in Org
| 225:#+begin_src org
| 234:#+begin_src org
| 241:** Code Blocks in Babel
| 249:#+begin_src org
| 268:* Source Code Execution
| 289:#+begin_src ruby
| 304:#+begin_src sh
| 322:#+begin_src R :colnames yes
| 346:#+begin_src ditaa :file blue.png :cmdline -r
| 360:** Capturing the Results of Code Evaluation
| 385:#+begin_src python :results value
| 414:#+begin_src python :results output
| 429:** Session-based Evaluation
| 453:** Arguments to Code Blocks
| 469:#+begin_src python
| 512:#+begin_src emacs-lisp
| 539:** In-line Code Blocks
| 546:** Code Block Body Expansion
| 579:#+begin_src emacs-lisp :rownames yes :var data=user-data
| 585:#+begin_src emacs-lisp
| 593:** A Meta-programming Language for Org-mode
| 647:#+begin_src 

Re: [O] A simple way to search only headlines

2013-06-11 Thread Suvayu Ali
Hi Thorsten,

On Tue, Jun 11, 2013 at 04:42:28PM +0200, Thorsten Jolitz wrote:
 Suvayu Ali fatkasuvayu+li...@gmail.com writes:
 
  I wonder if semantic search can be leveraged to achieve the same.  It
  might open other possibilities: searching only links, list items, source
  blocks, ...  I think you get the point.  :-p
 
 navi-mode.el works for Org-mode buffers too, e.g. using 

I think you misunderstood somewhat what I was suggesting.

As far as I understand, navi-mode uses an interface like occur; it
presents a separate buffer with the results which you can then use to
navigate to the results.  Am I correct?

What I was suggesting (and how I understood the OPs question) was, to
restrict regular (i)search to headlines.  Consider the following example
Org buffer:


  * Top heading
  
  ** Sub-heading 1
  + List entry
  + Another entry with an enumerated list
1. Foo
2. Bar
  
  ** Another sub-heading


Now with such restriction enabled, `C-s A n o t h e r' will navigate to
the headline (just like regular isearch-forward)

  ** Another sub-heading

not the list item

  + Another entry with an enumerated list

As far as I know, functionality like this exists for traditional source
code buffers using semantic search.  I was wondering if it is possible
to leverage that mechanism to get the behaviour described above.  If it
is indeed possible, it could be hacked to work for other Org syntax
elements like links, lists, source blocks, drawers, etc.

Hopefully I didn't misunderstand your post and I was clearer expressing
myself this time.

Cheers,

-- 
Suvayu

Open source is the future. It sets us free.



Re: [O] A simple way to search only headlines

2013-06-11 Thread Thorsten Jolitz
Suvayu Ali fatkasuvayu+li...@gmail.com writes:

Hi Suvayu,

 On Tue, Jun 11, 2013 at 04:42:28PM +0200, Thorsten Jolitz wrote:
 Suvayu Ali fatkasuvayu+li...@gmail.com writes:
 
  I wonder if semantic search can be leveraged to achieve the same.  It
  might open other possibilities: searching only links, list items, source
  blocks, ...  I think you get the point.  :-p
 
 navi-mode.el works for Org-mode buffers too, e.g. using 

 I think you misunderstood somewhat what I was suggesting.

 As far as I understand, navi-mode uses an interface like occur; it
 presents a separate buffer with the results which you can then use to
 navigate to the results.  Am I correct?

yes, it works on top of occur-mode in a separate buffer, but *Navi*
buffer are permanent, and there can exist many of them at the same time. 

 What I was suggesting (and how I understood the OPs question) was, to
 restrict regular (i)search to headlines.  
[...]
 As far as I know, functionality like this exists for traditional source
 code buffers using semantic search.  I was wondering if it is possible
 to leverage that mechanism to get the behaviour described above.  If it
 is indeed possible, it could be hacked to work for other Org syntax
 elements like links, lists, source blocks, drawers, etc.

 Hopefully I didn't misunderstand your post and I was clearer expressing
 myself this time.

I think I more or less understood what the thread was about, but thanks
anyway for the clarification. Of course navi-mode does not offer
semantic search within an Org-mode buffer. But for practical purposes
it might be worth mentioning that typing one digit between 1 and 8 and
then C-s or C-r in the *Navi* buffer lets you already search easily only
in the headlines of an Org file. And many other views on a file are
possible, that can then be searched by standard commands. With keyboard
macros and switching between original buffer and *Navi* buffer (and
using org-mark-element e.g.), a lot can be achieved without the need of
writing any elisp code.

-- 
Cheers,
Thorsten




Re: [O] A simple way to search only headlines

2013-06-10 Thread Sebastien Vauban
Hi Nick,

Nick Dokos wrote:
 The OP probably wants this in the global keymap, rather than in the
 org-mode-map: just like the agenda dispatcher C-c a, this functionality is
 useful outside an org file.

 (global-set-key (kbd C-M-h) (lambda () (interactive) (org-agenda nil s 
 )))

Not sure to understand when this functionality would be useful outside of Org.
Can you explain?

Best regards,
  Seb

-- 
Sebastien Vauban




Re: [O] A simple way to search only headlines

2013-06-10 Thread Nick Dokos
Sebastien Vauban sva-n...@mygooglest.com
writes:

 Hi Nick,

 Nick Dokos wrote:
 The OP probably wants this in the global keymap, rather than in the
 org-mode-map: just like the agenda dispatcher C-c a, this functionality is
 useful outside an org file.

 (global-set-key (kbd C-M-h) (lambda () (interactive) (org-agenda nil s 
 )))

 Not sure to understand when this functionality would be useful outside of Org.
 Can you explain?


I meant org buffer: you might want to issue the command from an
arbitrary buffer, not just an org mode buffer, so the key should be
defined globally.

-- 
Nick




Re: [O] A simple way to search only headlines

2013-06-10 Thread Nick Dokos
Sebastien Vauban sva-n...@mygooglest.com
writes:

 Hi Nick,

 Nick Dokos wrote:
 Sebastien Vauban sva-n...@mygooglest.com writes:
 Nick Dokos wrote:
 The OP probably wants this in the global keymap, rather than in the
 org-mode-map: just like the agenda dispatcher C-c a, this functionality is
 useful outside an org file.

 (global-set-key (kbd C-M-h) (lambda () (interactive) (org-agenda nil s 
 )))

 Not sure to understand when this functionality would be useful outside of 
 Org.
 Can you explain?

 I meant org buffer: you might want to issue the command from an
 arbitrary buffer, not just an org mode buffer, so the key should be
 defined globally.

 I still don't understand.


You understand all too well :-)

 Here, the command is for searching among (Org) headlines of the current buffer
 -- see the restriction . I don't see how it would make sense to call that
 on something other than an Org mode buffer?

 Maybe you missed the  restriction?  Or do I miss something else?


I did. Sorry about that.

-- 
Nick




Re: [O] A simple way to search only headlines

2013-06-07 Thread Xebar Saram
Thank you both Thorsten and Seb, i really appreciate the help!

Seb, you wrote: The programming equivalent to C-c a s is:

(org-agenda nil s)

That's what you'd have to bind to a key (using a lambda function).

im a complete neewb and dont really have any idea on how to do the above,
can you show me an example?

Best

Z


On Tue, Jun 4, 2013 at 3:50 AM, Sebastien Vauban sva-n...@mygooglest.comwrote:

 Hello Xebar,

  Or, for a pure Org solution:
 
C-c a  s *salsa dance
 
  searches for terms appearing only *in the headline* (including tags).
 
  That's great ,i appreciate it!
 
  Seb, is there a way to quick bind a key to the above series of commands?

 The programming equivalent to C-c a s is:

 (org-agenda nil s)

 That's what you'd have to bind to a key (using a lambda function).

 What you want is the restriction to the current buffer as well. You should
 update the above, looking at the doc of `org-agenda' (sorry, no time now
 to do
 it).

 BTW, how to find that you have to bind `org-agenda'?  Simply `C-h k',
 followed
 by the key binding for which you want to know more (here, `C-c a'), such
 as:
 which function does it call?

 Best regards,
   Seb

 --
 Sebastien Vauban





Re: [O] A simple way to search only headlines

2013-06-07 Thread Richard Lawrence
Xebar Saram zelt...@gmail.com writes:

 Thank you both Thorsten and Seb, i really appreciate the help!

 Seb, you wrote: The programming equivalent to C-c a s is:

 (org-agenda nil s)

 That's what you'd have to bind to a key (using a lambda function).

 im a complete neewb and dont really have any idea on how to do the above,
 can you show me an example?

I think you're looking for something like:

(define-key org-mode-map (kbd C-M-h) (lambda () (org-agenda nil s )))

You could put a line like that in your .emacs.  Here's what it does:
#+BEGIN_SRC emacs-lisp
(define-key;; insert a new keybinding
  org-mode-map ;; into the Org mode map (so this won't affect bindings in 
non-Org buffers)

  ;; This is the key we're binding: C-M-h, for headline search
  ;; You can use whatever key you like, but you might want to check first that 
it isn't
  ;; already bound to something else (e.g., via C-h k from an Org buffer).
  ;; The kbd macro converts a string representation to the appropriate key code.
  (kbd C-M-h)
  
  ;; This is the function to run when the key is pressed.  The lambda
  ;; form creates an anonymous function which calls org-agenda with
  ;; the s argument and a restriction to current buffer.
  (lambda () (org-agenda nil s )))
#+END_SRC

Best,
Richard




Re: [O] A simple way to search only headlines

2013-06-07 Thread Xebar Saram
Hi Richard

Fantastic, thx alot for the code snippet and detailed explanation, it
really helps to understand what goes on. unfortunately i get an error:

Wrong type argument: commandp, (lambda nil (org-agenda nil s ))

any clue?

best

Z.


On Fri, Jun 7, 2013 at 5:50 PM, Richard Lawrence 
richard.lawre...@berkeley.edu wrote:

 Xebar Saram zelt...@gmail.com writes:

  Thank you both Thorsten and Seb, i really appreciate the help!
 
  Seb, you wrote: The programming equivalent to C-c a s is:
 
  (org-agenda nil s)
 
  That's what you'd have to bind to a key (using a lambda function).
 
  im a complete neewb and dont really have any idea on how to do the above,
  can you show me an example?

 I think you're looking for something like:

 (define-key org-mode-map (kbd C-M-h) (lambda () (org-agenda nil s
 )))

 You could put a line like that in your .emacs.  Here's what it does:
 #+BEGIN_SRC emacs-lisp
 (define-key;; insert a new keybinding
   org-mode-map ;; into the Org mode map (so this won't affect bindings in
 non-Org buffers)

   ;; This is the key we're binding: C-M-h, for headline search
   ;; You can use whatever key you like, but you might want to check first
 that it isn't
   ;; already bound to something else (e.g., via C-h k from an Org buffer).
   ;; The kbd macro converts a string representation to the appropriate key
 code.
   (kbd C-M-h)

   ;; This is the function to run when the key is pressed.  The lambda
   ;; form creates an anonymous function which calls org-agenda with
   ;; the s argument and a restriction to current buffer.
   (lambda () (org-agenda nil s )))
 #+END_SRC

 Best,
 Richard





Re: [O] A simple way to search only headlines

2013-06-07 Thread Richard Lawrence
Xebar Saram zelt...@gmail.com writes:

 Hi Richard

 Fantastic, thx alot for the code snippet and detailed explanation, it
 really helps to understand what goes on. unfortunately i get an error:

 Wrong type argument: commandp, (lambda nil (org-agenda nil s ))

Ah, sorry about that, should have tested my code before I sent it!

The problem is that you have to give a /command/ to define-key (i.e., a
function with a call to `interactive' in its definition).

This should do it:

(define-key org-mode-map (kbd C-M-h) (lambda () (interactive) (org-agenda nil 
s )))

Best,
Richard




Re: [O] A simple way to search only headlines

2013-06-07 Thread Nick Dokos
Richard Lawrence richard.lawre...@berkeley.edu writes:

 Xebar Saram zelt...@gmail.com writes:

 Thank you both Thorsten and Seb, i really appreciate the help!

 Seb, you wrote: The programming equivalent to C-c a s is:

 (org-agenda nil s)

 That's what you'd have to bind to a key (using a lambda function).

 im a complete neewb and dont really have any idea on how to do the above,
 can you show me an example?

 I think you're looking for something like:

 (define-key org-mode-map (kbd C-M-h) (lambda () (org-agenda nil s )))

 You could put a line like that in your .emacs.

The OP probably wants this in the global keymap, rather than in 
the org-mode-map: just like the agenda dispatcher C-c a, this
functionality is useful outside an org file.

--8---cut here---start-8---
(global-set-key (kbd C-M-h) (lambda () (interactive) (org-agenda nil s 
)))
--8---cut here---end---8---

Also C-M-h runs mark-defun by default and it's not nice to usurp global
keys like that. I would suggest C-c s instead.

Using the global keymap also simplifies the initialization. In order to
put the key definition into the org-mode-map, the map has to be defined
already, i.e the define-key has to be done *after* org is loaded; so you
can't put it in an arbitrary place in .emacs. The safest way is to put
it in a hook (a list of no-argument functions that are executed after
the mode is set on a file):

(setq org-mode-hook
  '(
(function (lambda ()
   (define-key org-mode-map 
 (kbd C-M-h) (lambda ()
 (interactive)
 (org-agenda nil s )
; maybe followed by more functions in the list
   ) ; this paren end the list
  )  ; this paren closes the setq


Putting it in the global map instead bypasses this problem completely
since the global map is defined before .emacs is loaded. That's not to
say that the global map is always the right place to define a key: on
the contrary, most of the time it isn't. But in this case it is the
right place *and* putting the key definition there is simpler.

-- 
Nick




Re: [O] A simple way to search only headlines

2013-06-04 Thread Thorsten Jolitz
Xebar Saram zelt...@gmail.com writes:

 Thx Seb and Tassilo

 That's great ,i appreciate it!

 Seb, is there a way to quick bind a key to the above series of commands?

Just to add another method to search only headlines: use navi-mode.el

,-
| https://github.com/tj64/navi
`-

There is a tutorial on Worg:

,---
| http://orgmode.org/worg/org-tutorials/org-outside-org.html
`---

Using the 'org-outside-org.org' file of this tutorial as an example, if
you do (after installation of course)

,-
| (navi-search-and-switch)
| It is bound to M-s n.
`-

on this file, a (Occur like) *Navi* buffer pops up showing you the first
level headlines:

,
| 3 matches for ^\*  in buffer: org-outside-org.org
|  15:* Introduction
|  46:* Org-mode everywhere
| 926:* Screencasts
`

Typing '4' in the *Navi* buffer shows you the headlines up to level 4:

,--
| 30 matches for ^\*\*?\*?\*?  in buffer: org-outside-org.org
|  15:* Introduction
|  46:* Org-mode everywhere
|  50:** File Structuring
|  54:*** Orgstruct
|  94:*** Outline with Outshine
|  99: History and Credits
| 129: Installation
| 190: Outshine's fundamental idea
| 234: Fontification, Navigation and Structure Editing
| 285:** Subtree and Comment Editing
| 289:*** Introduction
| 308:*** Outorg
| 313: Introduction and Installation
| 337: Usage
| 392: Outorg vs Poporg
| 419:*** Poporg
| 428: Introduction
| 452: Installation
| 480: Usage
| 523: Known bugs
| 559: Caveats
| 590: History
| 614: Other tools
| 644: Python
| 711:** Remote Buffer Control
| 751:*** Navi-mode
| 756: About navi-mode
| 774: Installation
| 795: Usage
| 926:* Screencasts
`--

Since these headlines are the result of grep searches, they are *not*
folded outline (Org-mode) subtrees but just single lines of text, so you
can easily search them with the basic Emacs search commands (C-s and C-r
e.g.).

Of course you can do much more things in addition to searching
headlines. Just to give you two examples:

1. type 'E' in the *Navi* buffer and the buffer is put in *Navi-Edit*
mode, i.e.you can edit the headline in the *Navi* buffer and all edits
are immediately applied to the associated Org-mode file. This is perfect
for runnung Emacs keyboard macros only on the headlines of an Org-mode
(or outshine) buffer. Type 'C-c C-c' to go back to read-only *Navi*
mode.

2. with point on a headline in the *Navi* buffer, type 'e' and the
subtree at point will be offered for editing in a temporary Org-mode
buffer. This makes no sense for an .org file, of course, but is great
when you structure your source code files (e.g. Emacs Lisp files) with
headlines and use outshine.el, because then you can write all comment
sections in Org-mode instead of as outcommented text in a source code
buffer.

--
cheers,
Thorsten




Re: [O] A simple way to search only headlines

2013-06-04 Thread Sebastien Vauban
Hello Xebar,

 Or, for a pure Org solution:

   C-c a  s *salsa dance

 searches for terms appearing only *in the headline* (including tags).

 That's great ,i appreciate it!

 Seb, is there a way to quick bind a key to the above series of commands?

The programming equivalent to C-c a s is:

(org-agenda nil s)

That's what you'd have to bind to a key (using a lambda function).

What you want is the restriction to the current buffer as well. You should
update the above, looking at the doc of `org-agenda' (sorry, no time now to do
it).

BTW, how to find that you have to bind `org-agenda'?  Simply `C-h k', followed
by the key binding for which you want to know more (here, `C-c a'), such as:
which function does it call?

Best regards,
  Seb

-- 
Sebastien Vauban




Re: [O] A simple way to search only headlines

2013-06-03 Thread Sebastien Vauban
Tassilo Horn wrote:
 Xebar Saram zelt...@gmail.com writes:

 i was wondering if anyone knew of a way to search for text only in
 headlines and not the whole document? if not is it something one can
 put a feature request for?

 Use regular expression search or isearch.  The latter would be:

   C-u C-s \*+.*your-search-prase

Or, for a pure Org solution:

  C-c a  s *salsa dance

searches for terms appearing only *in the headline* (including tags).

Best regards,
  Seb

-- 
Sebastien Vauban




Re: [O] A simple way to search only headlines

2013-06-03 Thread Xebar Saram
Thx Seb and Tassilo

That's great ,i appreciate it!

Seb, is there a way to quick bind a key to the above series of commands?

best

Z


On Mon, Jun 3, 2013 at 3:48 AM, Sebastien Vauban sva-n...@mygooglest.comwrote:

 Tassilo Horn wrote:
  Xebar Saram zelt...@gmail.com writes:
 
  i was wondering if anyone knew of a way to search for text only in
  headlines and not the whole document? if not is it something one can
  put a feature request for?
 
  Use regular expression search or isearch.  The latter would be:
 
C-u C-s \*+.*your-search-prase

 Or, for a pure Org solution:

   C-c a  s *salsa dance

 searches for terms appearing only *in the headline* (including tags).

 Best regards,
   Seb

 --
 Sebastien Vauban





[O] A simple way to search only headlines

2013-06-01 Thread Xebar Saram
Hi guys

i was wondering if anyone knew of a way to search for text only in
headlines and not the whole document? if not is it something one can put a
feature request for?

kind regards

z.


Re: [O] A simple way to search only headlines

2013-06-01 Thread Tassilo Horn
Xebar Saram zelt...@gmail.com writes:

 i was wondering if anyone knew of a way to search for text only in
 headlines and not the whole document? if not is it something one can
 put a feature request for?

Use regular expression search or isearch.  The latter would be:

  C-u C-s \*+.*your-search-prase

Bye,
Tassilo