From mboxrd@z Thu Jan 1 00:00:00 1970 From: Adam Spiers Subject: adding subheadings Date: Sun, 15 Jul 2007 20:07:44 +0100 Message-ID: <20070715190744.GA10139@atlantic.linksys.moosehall> Reply-To: Adam Spiers Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IA9Rc-00021b-GC for emacs-orgmode@gnu.org; Sun, 15 Jul 2007 15:07:48 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IA9Rb-00020q-TO for emacs-orgmode@gnu.org; Sun, 15 Jul 2007 15:07:48 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IA9Rb-00020M-Mn for emacs-orgmode@gnu.org; Sun, 15 Jul 2007 15:07:47 -0400 Received: from mail.beimborn.com ([70.84.38.100]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1IA9Rb-00042h-8K for emacs-orgmode@gnu.org; Sun, 15 Jul 2007 15:07:47 -0400 Received: from mail.beimborn.com (localhost.localdomain [127.0.0.1]) by mail.beimborn.com (8.12.11.20060308/8.12.8) with ESMTP id l6FJ7jOA013779 for ; Sun, 15 Jul 2007 14:07:45 -0500 Received: from localhost (localhost [[UNIX: localhost]]) by mail.beimborn.com (8.12.11.20060308/8.12.11/Submit) id l6FJ7jfq013774 for emacs-orgmode@gnu.org; Sun, 15 Jul 2007 20:07:45 +0100 Content-Disposition: inline List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: org-mode mailing list Hi all, First post so go easy on me ;-) Would something like the following be of use to anyone other than me? (Suggested key-bindings at the bottom of the code.) --------- 8< --------- 8< --------- 8< --------- 8< --------- 8< --------- (defun org-new-subheading () "Add a new heading, demoted from the current heading level." (interactive) (org-insert-heading) (org-demote-subtree)) (defun org-new-subheading-todo (&optional arg) "Add a new TODO item, demoted from the current heading level. The TODO keyword for the new item can be specified by a numeric prefix argument, as with `org-todo'. Otherwise, if `org-subheading-todo-alist' is non-nil, it is used to map the new keyword from the current one, and if it is nil, the next TODO keyword in the sequence is used, or the first one if the current heading does not have one. This allows a TODO keyword hierarchy to be imposed, e.g. if org-subheading-todo-alist is '((\"MASTERPLAN\" . \"PROJECT\") (\"PROJECT\" . \"NEXTACTION\") (\"NEXTACTION\" . \"NEXTACTION\")) then invoking this function four times would yield: * MASTERPLAN ** PROJECT *** NEXTACTION **** NEXTACTION" (interactive "P") (save-excursion (org-back-to-heading) (looking-at org-todo-line-regexp)) (let* ((current-keyword (match-string 2)) (new-keyword (if arg (nth (1- (prefix-numeric-value arg)) org-todo-keywords-1) (or (and current-keyword (or (car (assoc current-keyword org-subheading-todo-alist)) (cadr (member current-keyword org-todo-keywords-1)))) (car org-todo-keywords-1))))) (org-new-subheading) (insert new-keyword " "))) (defcustom org-subheading-todo-alist nil "An associative map to help define which TODO keyword should be used for new subheadings, depending on the current heading's TODO keyword. See the documentation for `org-new-subheading-todo' for an example." :group 'org-todo :type '(alist :key-type (string :tag "Current heading keyword") :value-type (string :tag "New sub-heading keyword"))) (org-defkey org-mode-map [(meta j)] 'org-new-subheading) (org-defkey org-mode-map [(shift meta j)] 'org-new-subheading-todo) --------- 8< --------- 8< --------- 8< --------- 8< --------- 8< --------- I would have preferred to make the defcustom have a radio button list of existing TODO keywords for the alist keys and values, rather than freeform strings, but I couldn't figure out how to get it to refer to to org-todo-keywords-1. Finally, what's the preferred way to submit patches? Is there a revision-controlled repository available anywhere? Cheers, Adam