From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: A simple way to search only headlines Date: Sat, 08 Jun 2013 01:25:11 -0400 Message-ID: <87ip1pkwco.fsf@pierrot.dokosmarshall.org> References: <87sj11a8yq.fsf@thinkpad.tsdh.de> <86y5arocrz.fsf@somewhere.org> <86k3mae2mo.fsf@somewhere.org> <87mwr1egjr.fsf@berkeley.edu> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42095) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UlBec-0001tg-5U for emacs-orgmode@gnu.org; Sat, 08 Jun 2013 01:25:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UlBea-0001oP-SK for emacs-orgmode@gnu.org; Sat, 08 Jun 2013 01:25:30 -0400 Received: from plane.gmane.org ([80.91.229.3]:49786) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UlBea-0001oI-L5 for emacs-orgmode@gnu.org; Sat, 08 Jun 2013 01:25:28 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UlBeW-00080n-4E for emacs-orgmode@gnu.org; Sat, 08 Jun 2013 07:25:24 +0200 Received: from pool-108-7-96-134.bstnma.fios.verizon.net ([108.7.96.134]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 08 Jun 2013 07:25:24 +0200 Received: from ndokos by pool-108-7-96-134.bstnma.fios.verizon.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 08 Jun 2013 07:25:24 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Richard Lawrence writes: > Xebar Saram 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