When working with phone calls and tickets, I use Emacs in Org mode to pre-create the entry with the heading containing the current date and time. For obvious reasons, if not constantly using a new file (which would make history searches more difficult), I end up with a very long flat list of call headings and their respective contents.
I now want to change that, so that I get a top-level header with the year, a second-level header with the month and then a third-level header with the actual call entry.
In my trials, I manage to get the results when using the first entry inside the call file, but as soon as I get the second (third, fourth), the indentation is getting deeper with each entry. I also experimented with "post-editing" the automation (e.g. (org-insert-subheading t) (beginning-of-line) (delete-char 1) (end-of-line)
), but I find that very messy to the point that items like (org-insert-heading)
would have no meaning anymore.
The result shall look somewhat like this:
* <2019>
** <12>
*** call <date&time_of_call>
*** call <date&time_of_call>
* <2020>
** <01>
*** call <date&time_of_call>
*** call <date&time_of_call>
** <02>
*** call <date&time_of_call>
*** call <date&time_of_call>
...
My code so far looks like this (I call eltest
with a key shortcut):
(defvar sFilePath "~/Documents/Emacs/"
"Path to directory.")
(defvar sTestEntryYear "<%Y>"
"Year format string for entry headings.")
(defvar sTestEntryMonth "<%m>"
"Month format string for entry headings.")
(defvar sTestEntry "<%a, %Y-%m-%d %H:%M:%S>"
"Date & time format string for entry headings.")
(defun insert_test_template ()
"Insert the test template"
(interactive)
((lambda ()
(org-insert-subheading t)
(insert (concat "Calls " sNow " Call|WalkUp: ProblemDescription\n\n"))
(insert "template goes on here\n")
(insert "RESULT\n")
(insert "-> "))))
(defun eltest ()
"Add a new call entry."
(interactive)
(switch-to-buffer (find-file (concat sFilePath "Test.org")))
(widen)
(let ((sThisYear (format-time-string sTestEntryYear)) (sThisMonth (format-time-string sTestEntryMonth)) (sNow (format-time-string sTestEntry)))
(end-of-buffer)
(unless (org-goto-local-search-headings sThisYear nil t)
((lambda ()
(org-insert-heading nil nil t)
(insert (concat sThisYear "\n")))))
(end-of-buffer)
(unless (org-goto-local-search-headings sThisMonth nil t)
((lambda ()
(org-insert-subheading t)
(insert (concat sThisMonth "\n")))))
(end-of-buffer)
(unless (org-goto-local-search-headings sNow nil t)
((lambda ()
(insert_test_template))))
(while (progn
(previous-line 1)
(not (looking-at "^- Name : $"))))
(org-show-entry)
(end-of-line)))