Before we go too far, we should create a publishing file for the website announcement, and something for the journal.
** Clock in Tasks
Org has one task at a time that can be /clocked in/ keeping a timer. I use that as a /destination/ for collecting notes. For instance, capturing with a =c= allows me to just enter stuff in under that task without switching to it:
#+BEGIN_SRC emacs-lisp
(add-to-list 'org-capture-templates
'("c" "Currently clocked in task"))
#+END_SRC
Let's put a bullet item under that task:
#+BEGIN_SRC emacs-lisp
(add-to-list 'org-capture-templates
`("cc" "Item to Current Clocked Task" item
(clock)
"%i%?" :empty-lines 1))
#+END_SRC
We can select a /region/ and copy that using =c r=:
#+BEGIN_SRC emacs-lisp
(add-to-list 'org-capture-templates
`("cr" "Contents to Current Clocked Task" plain
(clock)
"%i" :immediate-finish t :empty-lines 1))
#+END_SRC
If we have copied anything into the clipboard, that information can be add to the current task using =c k=:
#+BEGIN_SRC emacs-lisp
(add-to-list 'org-capture-templates
`("ck" "Kill-ring to Current Clocked Task" plain
(clock)
"%c" :immediate-finish t :empty-lines 1))
#+END_SRC
Instead, if I am looking at some code, I can copy some code from a region, but use a helper function to create a /link/ to the original source code using =c f=:
#+BEGIN_SRC emacs-lisp
(add-to-list 'org-capture-templates
`("cf" "Code Reference with Comments to Current Task"
plain (clock)
"%(ha-org-capture-code-snippet \"%F\")\n\n %?"
:empty-lines 1))
#+END_SRC
If I want a reference to the code, without any comments, I call ~c l~:
#+BEGIN_SRC emacs-lisp
(add-to-list 'org-capture-templates
`("cl" "Link to Code Reference to Current Task"
plain (clock)
"%(ha-org-capture-code-snippet \"%F\")"
:empty-lines 1 :immediate-finish t))
#+END_SRC
** Capture Helper Functions
In order to have a capture back-ref to a function and its code, we need to use this:
#+BEGIN_SRC emacs-lisp
(require 'which-func)
#+END_SRC
This helper function given a code /type/ and the /function/, analyzes the current buffer in order to collects data about the source code file. It then creates a nice-looking template:
#+BEGIN_SRC emacs-lisp
(defun ha-org-capture-fileref-snippet (f type headers func-name)
#+END_%s" initial-txt type headers code-snippet type)))
#+END_SRC
For typical code references, we can get the label for Org's =SRC= block by taking the =major-mode= and removing the =-mode= part. We can then call the formatter we previously defined:
#+BEGIN_SRC emacs-lisp
(defun ha-org-capture-code-snippet (f)
"Given a file, F, this captures the currently selected text
within an Org SRC block with a language based on the current mode
(ha-org-capture-fileref-snippet f "SRC" org-src-mode func-name))))
#+END_SRC
Let's assume that we want to copy some text from a file, but it isn't source code, then this function makes an =EXAMPLE= of it.
#+BEGIN_SRC emacs-lisp
(defun ha-org-capture-clip-snippet (f)
"Given a file, F, this captures the currently selected text
within an Org EXAMPLE block and a backlink to the file."
(with-current-buffer (find-buffer-visiting f)
(ha-org-capture-fileref-snippet f "EXAMPLE" "" nil)))
#+END_SRC
** Code Capturing Functions
In order to easily call a capture for code, let's make two interactive functions, one just copies the stuff, and the other pulls up a capturing window for comments:
#+BEGIN_SRC emacs-lisp
(defun ha-code-to-clock (&optional start end)
"Send the currently selected code to the currently clocked-in org-mode task."
"Send the currently selected code (with comments) to the
currently clocked-in org-mode task."
(interactive)
(org-capture nil "f"))
#+END_SRC
* External Interface
** Emacs Server Control
Sure the Emacs application will almost always have the =server-start= going, however, I need to control it just a bit (because I often have two instances running on some of my machines). What /defines/ the Emacs instance for work changes ... often:
#+BEGIN_SRC emacs-lisp
(defun ha-emacs-for-work? ()
"Return non-nil when the Emacs application's location matches as one for work.
Currently, this is the `emacs-plus' app that I have built with
the native-comp model, but I reserve the right to change this."
If we put something on the clipboard using =xclip= or something, and then
perhaps =emacsclient= could call this function to put those contents into clocked in task.
#+BEGIN_SRC emacs-lisp
(defun ha-external-capture-to-org ()
"Calls `org-capture-string' on the contents of the Apple clipboard."
(interactive)
(org-capture-string (ha-org-clipboard) "ck")
(ignore-errors
(delete-frame)))
#+END_SRC
The =en= script is used as the last pipe entry on the command line, this displays the output, and then copies the contents into the Emacs-based engineering notebook at the currently clocked in task.