emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* New headline after no content (empty headline)
@ 2014-03-15 21:24 Brady Trainor
  2014-03-17  0:49 ` Bastien
  0 siblings, 1 reply; 7+ messages in thread
From: Brady Trainor @ 2014-03-15 21:24 UTC (permalink / raw)
  To: emacs-orgmode



I am revisiting a workflow that I have a hard time letting go of, despite 
it's unintended use in Org-mode. 

That is, I like to visually separate groups of headlines by simply having a 
couple of empty headlines. This allows more nimble and simple use-case of 
manually sorting buildup of headlines by quick and flexible tagging (and 
easy removal of such), and minimal visual aid of a couple empty headlines. 

This way, I can so sorting and orienting of tasks without much commitment, 
allowing me to start the process all over again quickly if I feel I 
didn't "rotate my space" the right way. 

My problem is that using the default new headline commands, it removes the 
whitespace from previous lines, so "* " becomes "*\n* ", instead of my 
desired "* \n* ". 

So, I started trying to read the org.el file. I thought I had found 
the "offending" line, (my L7614,) finding 

	  ;; If we insert after content, move there and clean up whitespace
	  (when respect-content
	    (org-end-of-subtree nil t)
	    (skip-chars-backward " \r\n")
	    (and (looking-at "[ \t]+") (replace-match ""))
	    (unless (eobp) (forward-char 1))
	    (when (looking-at "^\\*")
	      (unless (bobp) (backward-char 1))
	      (insert "\n")))

I thought to try substituting "[ \t]+" with "[\t]+", and byte compiled the 
file. But this did not solve. 

So, I never like to ask a question without having an answer myself, so I 
learned a little more enough about keyboard macros to generate the 
following somewhat simple and natural solution (natural in that it uses a 
similar unused key chord): 

    (fset 'new-starred-line
          [return ?* ? ])
    (global-set-key (kbd "C-M-<return>") 'new-starred-line)


So, what is my question? What am I lacking in my .el package reading 
skills? Why did my first fix not work? As a newb program hacker, am I 
approaching this right? Maybe best case is to understand more of the entire 
org.el file, but was trying to hack just enough. What would you have done? 


Regards, 

Brady

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

* Re: New headline after no content (empty headline)
  2014-03-15 21:24 New headline after no content (empty headline) Brady Trainor
@ 2014-03-17  0:49 ` Bastien
  2014-03-23  2:08   ` Brady Trainor
  0 siblings, 1 reply; 7+ messages in thread
From: Bastien @ 2014-03-17  0:49 UTC (permalink / raw)
  To: Brady Trainor; +Cc: emacs-orgmode

Hi Brady,

Brady Trainor <algebrat@uw.edu> writes:

> So, I started trying to read the org.el file. I thought I had found 
> the "offending" line, (my L7614,) finding 
>
> 	  ;; If we insert after content, move there and clean up whitespace
> 	  (when respect-content
> 	    (org-end-of-subtree nil t)
> 	    (skip-chars-backward " \r\n")
> 	    (and (looking-at "[ \t]+") (replace-match ""))
> 	    (unless (eobp) (forward-char 1))
> 	    (when (looking-at "^\\*")
> 	      (unless (bobp) (backward-char 1))
> 	      (insert "\n")))
>
> I thought to try substituting "[ \t]+" with "[\t]+", and byte compiled the 
> file. But this did not solve.

The idea behind (and (looking-at "[ \t]+") (replace-match "")) is to
remove whitespaces after the entry.  It generally happens with
non-empty headlines, so it's the correct move here.

What you want is not to remove only tabs, but to prevent removing
whitespaces when the string before the point matches "^\*+" -- so
that's what I did with this patch:

http://orgmode.org/cgit.cgi/org-mode.git/commit/?id=afffe03d

> So, I never like to ask a question without having an answer myself, so I 
> learned a little more enough about keyboard macros to generate the 
> following somewhat simple and natural solution (natural in that it uses a 
> similar unused key chord): 
>
>     (fset 'new-starred-line
>           [return ?* ? ])
>     (global-set-key (kbd "C-M-<return>") 'new-starred-line)
>
>
> So, what is my question? What am I lacking in my .el package reading 
> skills? Why did my first fix not work? As a newb program hacker, am I 
> approaching this right? Maybe best case is to understand more of the entire 
> org.el file, but was trying to hack just enough. What would you have done? 

I don't have a general rule, but what I found out over time is this:
when struggling to find a solution, it is very easy to forget about
the problem.  I try to discipline myself (1) stating the problem by
writing it (when the OP did not find the problem itself or didn't
write it in a way I can understand) and (2) limiting the solution
to the problem.  It sounds like simple common sense, but experience
shows common sense in this area is not that common.

Getting familiar with the code is also the only to understand what
the program does by reading the code, and to make sure your solution
does not have side-effects.

HTH,

-- 
 Bastien

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

* Re: New headline after no content (empty headline)
  2014-03-17  0:49 ` Bastien
@ 2014-03-23  2:08   ` Brady Trainor
  2014-03-23  8:33     ` Bastien
  0 siblings, 1 reply; 7+ messages in thread
From: Brady Trainor @ 2014-03-23  2:08 UTC (permalink / raw)
  To: emacs-orgmode

Bastien <bzg <at> gnu.org> writes:

> 
> Hi Brady,
> 
> Brady Trainor <algebrat <at> uw.edu> writes:

> > 	  (when respect-content

> > 	    (and (looking-at "[ \t]+") (replace-match ""))

> > I thought to try substituting "[ \t]+" with "[\t]+", and byte compiled the 
> > file. But this did not solve.

> What you want is not to remove only tabs, but to prevent removing
> whitespaces when the string before the point matches "^\*+" -- so
> that's what I did with this patch:
> 
> http://orgmode.org/cgit.cgi/org-mode.git/commit/?id=afffe03d

Thank you much for taking the time to fix my fix and add the patch. 

However, my fix was wrong, I should not have been looking inside the
=respect content= case. My original intention was to modify the
=insert-org-heading=, not =org-insert-heading-respect-content=. I was that
lost. 

Your help and encouragement pushed me to find the `source` of my problem. 
For this, I looked for ways to step through the code, ala some type of
debugger, and I fell upon Emacs' default, Edebugger. (Simply reading org.el
was, um, not efficient by itself.)

So, I "instrumented" the =defun=s, in the end both of =org-insert-heading=
and =org-N-empty-lines-before-current= (via =C-u C-M-x=) and deleting
org.elc. This way, testing =M-RET= in an org file, I could =SPACE= through
org.el while watching the org file buffer for changes (and *Messages*,
though that was more or less awkward for me). 

So, here are my changes that give me my desired behavior, modifying in the
function =org-N-empty-lines-before-current= which follows right after
function =org-insert-heading=. 

Originally

    (if (looking-back "\\s-+" nil 'greedy)
	(replace-match ""))
    (or (bobp) (insert "\n"))

I changed this to 

    (unless (looking-back "\* \n") ; don't damage empty headlines
      (if (looking-back "\\s-+" nil 'greedy)
	  (replace-match ""))
      (or (bobp) (insert "\n"))
      )

This feels a bit ad-hoc, as I don't completely understand all the stuff even
in =defun org-insert-heading...=, and likely a fix should be made taking
into account all desired functionality (but I'd worry to break something
else). Let's call it organic! /Someday/, I'd like to understand the org.el
better. 

I haven't learned how to patch, I've barely started gitting about a month
ago for backing up files. I guess I should clone the Org-mode source soon,
for starters. 

Thanks again! 

Brady

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

* Re: New headline after no content (empty headline)
  2014-03-23  2:08   ` Brady Trainor
@ 2014-03-23  8:33     ` Bastien
  2014-03-28  5:57       ` Brady Trainor
  0 siblings, 1 reply; 7+ messages in thread
From: Bastien @ 2014-03-23  8:33 UTC (permalink / raw)
  To: Brady Trainor; +Cc: emacs-orgmode

Hi Brady,

Brady Trainor <algebrat@uw.edu> writes:

> Thanks again!

you're welcome---does the Org version that comes from the maint
branch still needs a fix?  If so, can you describe the problem
again?

Here is how to use Org from maint

~$ git clone git://orgmode.org/org-mode.git
~$ git checkout maint
~$ make autoloads

Then update your load-path to use the correct directory.

HTH,

-- 
 Bastien

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

* Re: New headline after no content (empty headline)
  2014-03-23  8:33     ` Bastien
@ 2014-03-28  5:57       ` Brady Trainor
  2014-03-31  5:55         ` Bastien
  0 siblings, 1 reply; 7+ messages in thread
From: Brady Trainor @ 2014-03-28  5:57 UTC (permalink / raw)
  To: emacs-orgmode


Bastien <bzg <at> gnu.org> writes:

> ---does the Org version that comes from the maint branch 
> still needs a fix?  If so, can you describe the problem
> again?


I did test the `maint` branch today. The behavior was not ideal for my 
funny use-case.

For `org-insert-heading' (M-RET), I wanted the following action on empty 
headlines:

"* " |--> "* \n* ", rather than "*\n* ".

This patch may be suitable:

(org.el)

==========================

diff --git a/lisp/org.el b/lisp/org.el
index 6d6fbeb..86eb347 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7685,9 +7685,10 @@ This is important for non-interactive uses of the 
command."
 So this will delete or add empty lines."
   (save-excursion
     (goto-char (point-at-bol))
-    (if (looking-back "\\s-+" nil 'greedy)
-    (replace-match ""))
-    (or (bobp) (insert "\n"))
+    (unless (looking-back "\* \n")
+      (if (looking-back "\\s-+" nil 'greedy)
+      (replace-match ""))
+      (or (bobp) (insert "\n")))
     (while (> N 0)
       (insert "\n")
       (setq N (1- N)))))

==========================

Thank you!

Brady

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

* Re: New headline after no content (empty headline)
  2014-03-28  5:57       ` Brady Trainor
@ 2014-03-31  5:55         ` Bastien
  2014-03-31  6:26           ` Brady Trainor
  0 siblings, 1 reply; 7+ messages in thread
From: Bastien @ 2014-03-31  5:55 UTC (permalink / raw)
  To: Brady Trainor; +Cc: emacs-orgmode

Hi Brady,

Brady Trainor <algebrat@uw.edu> writes:

> For `org-insert-heading' (M-RET), I wanted the following action on empty 
> headlines:
>
> "* " |--> "* \n* ", rather than "*\n* ".

I'm not sure I understand this, can you make it more explicit?

Thanks!

-- 
 Bastien

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

* Re: New headline after no content (empty headline)
  2014-03-31  5:55         ` Bastien
@ 2014-03-31  6:26           ` Brady Trainor
  0 siblings, 0 replies; 7+ messages in thread
From: Brady Trainor @ 2014-03-31  6:26 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode


On 3/30/2014 10:55 PM, Bastien wrote:
> Hi Brady,
>
> Brady Trainor <algebrat@uw.edu> writes:
>
>> For `org-insert-heading' (M-RET), I wanted the following action on empty
>> headlines:
>>
>> "* " |--> "* \n* ", rather than "*\n* ".
>
> I'm not sure I understand this, can you make it more explicit?
>
> Thanks!
>

I mean that if I use org-insert heading on an empty headline, it removes 
the space after asterisk(s). This then means that what was previously an 
empty heading (with a space), becomes just asterisk(s) no longer 
interpreted by org-mode as a heading.

I concluded that the space was removed by 
org-N-empty-lines-before-current function, where `(unless (looking-back 
"\* \n")...` prevents `org-N-...` from removing that space.

Thank you,

Brady

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

end of thread, other threads:[~2014-03-31  6:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-15 21:24 New headline after no content (empty headline) Brady Trainor
2014-03-17  0:49 ` Bastien
2014-03-23  2:08   ` Brady Trainor
2014-03-23  8:33     ` Bastien
2014-03-28  5:57       ` Brady Trainor
2014-03-31  5:55         ` Bastien
2014-03-31  6:26           ` Brady Trainor

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