Compare commits
2 Commits
9a20b487c8
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 33e63ccda2 | |||
| 20e426dc69 |
111
config.org
111
config.org
@@ -264,91 +264,6 @@
|
||||
'org-insert-heading-after-current)))
|
||||
#+end_src
|
||||
|
||||
** Journal Files
|
||||
Sometimes I like to make a todo list for a day if I've a lot to do,
|
||||
or write a little bit about a day if it's been particularly
|
||||
eventful. In both of these cases, it would be nice to just be able
|
||||
to hit a particular keybinding and have the right buffer pop up. I
|
||||
was using =org-roam='s daily notes feature for this, but I ended up
|
||||
getting annoyed with =org-roam= (too many features for my taste
|
||||
lol).
|
||||
|
||||
The convention I'm going for is for is having a particular
|
||||
directory for these journal entries and then give each file a name
|
||||
like "2022-10-30.org". With that in mind, there are two obvious
|
||||
variables to define:
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(defvar journal-directory
|
||||
"~/Documents/org/journal"
|
||||
"Directory to store journal entries in.")
|
||||
|
||||
(defvar journal-filename-format
|
||||
"%F"
|
||||
"Date format to use for journal entries' filenames (not including
|
||||
the \".org\" extension)")
|
||||
#+end_src
|
||||
|
||||
I can't be bothered to handle [[help:journal-directory][journal-directory]] not existing in the
|
||||
main code, so I'm just going to make sure it exists here. The
|
||||
second argument to [[help:make-directory][make-directory]] specifies to create parent
|
||||
directories too if necessary.
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(unless (file-directory-p journal-directory)
|
||||
(make-directory journal-directory t))
|
||||
#+end_src
|
||||
|
||||
The next step is to define a function to determine the filename for
|
||||
today's journal entry. This is fairly straightforward, using
|
||||
[[help:format-time-string][format-time-string]] to get the current date in the right format,
|
||||
then sticking that together with the directory, extension, etc.
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(defun journal-entry-filename ()
|
||||
"Returns the filename for today's journal entry."
|
||||
(let ((date-string (format-time-string journal-filename-format)))
|
||||
(concat journal-directory "/" date-string ".org")))
|
||||
#+end_src
|
||||
|
||||
If the journal entry doesn't exist yet, I want it to be populated
|
||||
with the long-form date as the title:
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(defvar journal-title-date-format
|
||||
"%A, %-e %B %+4Y"
|
||||
"The date format to use for journal entries' titles.")
|
||||
|
||||
(defun insert-default-journal-entry-contents ()
|
||||
"Insert the default journal entry contents (currently this is
|
||||
just today's long-form date as a title) into the current buffer."
|
||||
(insert "#+TITLE: "
|
||||
(format-time-string journal-title-date-format)
|
||||
"\n\n"))
|
||||
#+end_src
|
||||
|
||||
We can now make a function to open today's journal entry fairly
|
||||
trivially using [[help:find-file][find-file]], and the above utilities. It should be
|
||||
interactive, as this is what we'll be calling in the key binding.
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(defun open-journal-entry ()
|
||||
"Opens today's journal entry, populating it with the default
|
||||
contents if it does not already exist."
|
||||
(interactive)
|
||||
(let* ((filename (journal-entry-filename))
|
||||
(new-entry (not (file-exists-p filename))))
|
||||
(find-file filename)
|
||||
(when new-entry
|
||||
(insert-default-journal-entry-contents))))
|
||||
#+end_src
|
||||
|
||||
Finally, [[help:open-journal-entry][open-journal-entry]] can be bound to a key:
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(global-set-key (kbd "C-c t") 'open-journal-entry)
|
||||
#+end_src
|
||||
|
||||
** Source Blocks
|
||||
Pressing tab inside a source block should indent appropriately for its
|
||||
language.
|
||||
@@ -1270,7 +1185,7 @@
|
||||
(setq Man-notify-method 'pushy)
|
||||
#+end_src
|
||||
|
||||
** Script-Fu Mode
|
||||
** Script-Fu
|
||||
GIMP has a scheme-based language -- Script-Fu -- built into it that
|
||||
you can use to script things (based). Sadly, the built-in console
|
||||
is rather lackluster as a coding environment. Happily, there /is/
|
||||
@@ -1280,12 +1195,12 @@
|
||||
|
||||
It's things like this that make me really glad I switched to Emacs
|
||||
because this is ridiculously cool. By my definition of "cool"
|
||||
anyway -- what can I say, I'm a massive nerd.
|
||||
anyway (what can I say, I'm a massive nerd).
|
||||
|
||||
I should probably extract this and make a standalone package out of
|
||||
it and stick it on Melpa at some point.
|
||||
|
||||
*** REPL Mode
|
||||
*** REPL
|
||||
The Script-Fu server request format is very simple:
|
||||
|
||||
| Bytes | Description |
|
||||
@@ -1340,7 +1255,7 @@
|
||||
|
||||
The response format is similarly simple:
|
||||
|
||||
| Bytes | Content |
|
||||
| Bytes | Description |
|
||||
|-------+-----------------------------------------|
|
||||
| 0 | 'G' magic byte (47h) |
|
||||
| 1 | Status code -- 0 on success, 1 on error |
|
||||
@@ -1397,8 +1312,8 @@
|
||||
(interactive)
|
||||
(let ((buffer (get-buffer-create "*Script-Fu REPL*")))
|
||||
(when (not (comint-check-proc buffer))
|
||||
(make-comint-in-buffer "Script-Fu REPL" buffer
|
||||
script-fu-repl-server)
|
||||
(make-comint-in-buffer "Script-Fu REPL"
|
||||
buffer script-fu-repl-server)
|
||||
(with-current-buffer buffer (script-fu-repl-mode)))
|
||||
(pop-to-buffer buffer '((display-buffer-in-direction)
|
||||
(direction . below)
|
||||
@@ -1406,7 +1321,7 @@
|
||||
buffer))
|
||||
#+end_src
|
||||
|
||||
*** Code Editing Mode
|
||||
*** Code Editing
|
||||
With the client stuff done, we can define the code editing mode:
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
@@ -1414,7 +1329,9 @@
|
||||
#+end_src
|
||||
|
||||
Now to define something to send an expression or region to the
|
||||
REPL:
|
||||
REPL. Since =script-fu-repl= returns the buffer we can use that
|
||||
to transparently start a REPL or get the existing one if one's
|
||||
already running.
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(defun script-fu-mode-send-region-or-sexp ()
|
||||
@@ -1425,21 +1342,19 @@
|
||||
(buffer-substring-no-properties start end))
|
||||
(thing-at-point 'sexp t))))
|
||||
(if (not code) (message "No code to send.")
|
||||
(let* ((repl-buffer (script-fu-repl))
|
||||
(repl-proc (get-buffer-process repl-buffer)))
|
||||
(let* ((repl-proc (get-buffer-process (script-fu-repl))))
|
||||
(script-fu-repl-send repl-proc code)))))
|
||||
|
||||
(define-key script-fu-mode-map (kbd "C-c C-c")
|
||||
'script-fu-mode-send-region-or-sexp)
|
||||
#+end_src
|
||||
|
||||
And finally a similar thing for the whole file:
|
||||
And finally, a similar thing for the whole file:
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(defun script-fu-mode-send-file ()
|
||||
(interactive)
|
||||
(let* ((repl-buffer (script-fu-repl))
|
||||
(repl-proc (get-buffer-process repl-buffer))
|
||||
(let* ((repl-proc (get-buffer-process (script-fu-repl)))
|
||||
(buffer-contents
|
||||
(buffer-substring-no-properties (point-min)
|
||||
(point-max))))
|
||||
|
||||
Reference in New Issue
Block a user