URI: 
       ADD ACCESS TIMES TO ORG-MODE NOTES
       
       
       
       
       Preamble
       ----------------------------------------------------------------------
       I use Emacs, `org-mode', and `org-roam' as the foundation of my
       personal knowledge repository. It's a fine system that has served me
       well. The feature that I appreciate the most is the easy integration
       of my `org-mode' notes into my `org-mode' agenda. By inserting
       timestamps throughout my documents I can build a temporal
       representation of my work. In other words, I can see what I worked on
       yesterday, last week, or last month. I love being able to see what
       I've written about in days past. This is a small, helpful activity
       that dispells my usual anxious fear that I'm not learning
       anything. Alls it takes is a simple timestamp added to the note along
       with whatever else ideas I've written. Huzzah!
       
       
       Elisp
       ----------------------------------------------------------------------
       I wrote some Elisp to simplify the process of adding timestamps. The
       idea is simple: when invoked, the `roygbyte/org-touch' function adds a
       timestamp into the enclosing headline's timestamp drawer. If that
       drawer doesn't exist, it will create it first. Surprisingly, there's a
       lot of code just to perform that operation, which would only take a
       couple manual keystrokes by a clever operator. Anywho, I'm very happy
       with this approach. It is actually the second bit of code I've used
       for adding timestamps. My first prototype was copied from somewhere on
       the web. It added a timestamp at `(point)'. This was initially nice,
       because the timestamp appeared in line with other content and could be
       used to structure thoughts more temporally. But overtime they have
       become very cluttered. Moving the timestamp into a drawer is the best
       direction for this feature, and I wish I started there first! Oh well.
       
       ,----
       |   (bind-key "C-c t" 'roygbyte/org-touch org-mode-map)
       |     
       |   (defun roygbyte/org-touch ()
       |     "Insert timestamp into the nearest enclosing org heading."
       |     (interactive)
       |     (roygbyte/org-find-or-insert-drawer "TIMESTAMPS")
       |     (roygbyte/org-timestamp-insert-into-drawer "TIMESTAMPS"))
       | 
       |   (defun roygbyte/org-timestamp-insert-into-drawer (name)
       |     "Inserts a timestamp into the drawer given by NAME at the nearest
       |   enclosing org heading."
       |     (save-excursion
       |       (org-back-to-heading-or-point-min t)
       |       (let ((drawer (upcase name)))
       |         (let ((re (format "^[   ]*:%s:[   ]*$" (regexp-quote drawer)))
       Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
       Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
       Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
       Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
       Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
       Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
       Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
       | 
       |   (defun roygbyte/org-find-or-insert-drawer (name)
       |     "Insert drawer named by NAME at the nearest enclosing org heading,
       |   or at the top of the buffer if no org heading exists. In either
       |   case, drawer will be inserted after whatever other drawer may be
       |   present."
       |     (interactive "P")
       |     (let ((name (upcase (or name
       Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
       Happy helping ☃ here: You tried to output a spurious TAB character. This will break gopher. Please review your scripts. Have a nice day!
       |       (while (not point-start)
       |         (save-excursion ;; look for the drawer
       |           (org-back-to-heading-or-point-min t)
       |           (let ((re (format "^[   ]*:%s:[   ]*$" (regexp-quote name)))
       |                 (end (save-excursion (org-next-visible-heading 1)
       |                                      (point))))
       |             (when (re-search-forward re end t)
       |               (setf point-start (point)))))
       |         (when (not point-start)
       |           (save-excursion
       |             (org-back-to-heading-or-point-min t)
       |             (let ((re (format "[   ]*:END:[   ]*$"))
       |                   (end (save-excursion (org-next-visible-heading 1) ;; outline-next-heading work instead?
       |                                        (point))))
       |               (when (not (re-search-forward re end t 1))
       |                 (goto-char (line-end-position)))
       |               (org-insert-drawer nil name)
       |               ;; Remove the empty line that is inserted after drawer
       |               (forward-line 2)
       |               (delete-line)
       |               (setf point-start (point))))))
       |       point-start))
       `----