From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tassilo Horn Subject: Re: Using orgstruct-mode to structure source code Date: Wed, 03 Sep 2008 12:20:32 +0200 Message-ID: <87k5dtfs3z.fsf@thinkpad.tsdh.de> References: <87od35fx3a.fsf@thinkpad.tsdh.de> 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 1KapVY-0000i1-DX for emacs-orgmode@gnu.org; Wed, 03 Sep 2008 06:22:40 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KapVS-0000fx-W6 for emacs-orgmode@gnu.org; Wed, 03 Sep 2008 06:22:39 -0400 Received: from [199.232.76.173] (port=38293 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KapVS-0000fn-JZ for emacs-orgmode@gnu.org; Wed, 03 Sep 2008 06:22:34 -0400 Received: from deliver.uni-koblenz.de ([141.26.64.15]:18423) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KapVS-0005NF-5b for emacs-orgmode@gnu.org; Wed, 03 Sep 2008 06:22:34 -0400 In-Reply-To: (Carsten Dominik's message of "Wed, 3 Sep 2008 11:36:59 +0200") 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: Carsten Dominik Cc: emacs-orgmode@gnu.org Carsten Dominik writes: Hi Carsten, > "?..." is not a correct regular expression in Emacs. You are using > wildcard synax, it seems. No, I used (concat comment-starter "?...") to make the comment starter optional. But that's not fully correct. In elisp the comment starter may be there multiple times. So now I go with this: --8<---------------cut here---------------start------------->8--- (defun org-context-p (&rest contexts) (let* ((pos (point)) (comment-starter (replace-regexp-in-string "[ ]+$" "" (or comment-start ""))) (regexp-start (if (string= "" comment-start) "" (concat comment-start "*")))) (goto-char (point-at-bol)) (let ((ret (prog1 (or (and (memq 'table contexts) (looking-at (concat regexp-start "[ \t]*|"))) (and (memq 'headline contexts) (looking-at (concat regexp-start "\\*+"))) (and (memq 'item contexts) (looking-at (concat regexp-start "[ \t]*\\([-+*] \\|[0-9]+[.)] \\)")))) (goto-char pos)))) (message "org-context-p with regexp-start = %s ==> %s" regexp-start ret)))) --8<---------------cut here---------------end--------------->8--- Here's a short elisp test file: --8<---------------cut here---------------start------------->8--- ;;* First Headline ; org-context-p ==> t, no visible action ; org-context-p ==> nil, no visible action (defun foo () nil) ; org-context-p ==> nil, TAB deletes indentation! ; org-context-p ==> nil, TAB indents to nil's column ;;** Level2 ; org-context-p ==> t, TAB indents heading to nil's column (+ 1 2 3) ;;** Another Level2 (- 1 1) ;;*** Three ;;* Second part (progn (list 1 2 3) ; org-context-p ==> nil, TAB deletes indentation! (* 1 2 3)) ; org-context-p ==> nil, TAB deletes indentation! ;;* Third part ; org-context-p ==> t, TAB indents heading to ; column of (* 1 2 3) --8<---------------cut here---------------end--------------->8--- Behind the lines I've written what my redefinition of `org-context-p' returns and what TAB does (*without* these comments). As you can see `org-context-p' seems to work correctly, but TAB doesn't cycle through the visibility states but instead breakes indentation. And if I invoke `M-x org-cycle' on a headline nothing happens. As it seems, `org-context-p' is not the only function which has to be adapted to do the right thing if headlines are inside comments. > If you want to allow extra characters # and ; at the begin of the line, try > something like > > "[;#]*..." Yes, see the code above. > I am not sure if this will work, in particular if it will make > structure editing work. Sadly, it's not that easy. > Give it a try and send us a report, ok? Done! Bye, Tassilo