Compare commits
1 Commits
main
...
c59d1c8e73
| Author | SHA1 | Date | |
|---|---|---|---|
| c59d1c8e73 |
251
config.org
251
config.org
@@ -233,6 +233,35 @@
|
|||||||
(yas-reload-all)
|
(yas-reload-all)
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
* Calendar / Diary
|
||||||
|
Weeks start on Sunday by default, this can be changed to start on
|
||||||
|
Monday by setting [[help:calendar-week-start-day][calendar-week-start-day]] to 1:
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(setq calendar-week-start-day 1)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
Set latitute, longitude and location name to Bristol to get sunrise
|
||||||
|
and sunset times:
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(setq calendar-latitude 51.45)
|
||||||
|
(setq calendar-longitude -2.58)
|
||||||
|
(setq calendar-location-name "Bristol, UK")
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
Emacs needs to be told where the diary file is, of course:
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(setq diary-file "~/Documents/diary")
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
I want to use ISO-style dates in there:
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(calendar-set-date-style 'iso)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
* Org
|
* Org
|
||||||
** Code and Quote block shortcuts
|
** Code and Quote block shortcuts
|
||||||
I am a big fan of using =<s= for source blocks and =<q= for quotes;
|
I am a big fan of using =<s= for source blocks and =<q= for quotes;
|
||||||
@@ -264,6 +293,91 @@
|
|||||||
'org-insert-heading-after-current)))
|
'org-insert-heading-after-current)))
|
||||||
#+end_src
|
#+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
|
** Source Blocks
|
||||||
Pressing tab inside a source block should indent appropriately for its
|
Pressing tab inside a source block should indent appropriately for its
|
||||||
language.
|
language.
|
||||||
@@ -391,7 +505,116 @@
|
|||||||
(auto-mode . emacs)))
|
(auto-mode . emacs)))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
** Indentation
|
** Workflow States
|
||||||
|
I like to have =IN-PROGRESS= and =CANCELLED= workflow states as
|
||||||
|
well as the standard =TODO= and =DONE=. Cancelled items also want a
|
||||||
|
note attached explaining why. All this can be added by setting
|
||||||
|
[[help:org-todo-keywords][org-todo-keywords]]:
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(setq org-todo-keywords
|
||||||
|
'((sequence "TODO" "IN-PROGRESS" "|" "DONE" "CANCELLED(@)")))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
The ="|"= separates /needs further action/ states (before it) from
|
||||||
|
/no further action needed/ states (after it).
|
||||||
|
|
||||||
|
I also want to log the date and time when a note is marked as done:
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(setq org-log-done 'time)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
** Agenda
|
||||||
|
Time to try org-mode's agenda feature again I think. Last time I
|
||||||
|
didn't end up using it much, but I am /much/ more of an Emacs
|
||||||
|
addict now so I do forsee it actually surviving (this will be funny
|
||||||
|
to read in the future if not).
|
||||||
|
|
||||||
|
I want to show all TODOs in =.org= files under my top-level
|
||||||
|
=~/Documents/org= directory and any in this config itself. This is
|
||||||
|
done by enumerating all files under =~/Documents/org= with
|
||||||
|
[[help:directory-files-recursively][directory-files-recursively]], then setting [[help:org-agenda-files][org-agenda-files]] to this,
|
||||||
|
along with this config's path.
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(let ((org-docs
|
||||||
|
(directory-files-recursively "~/Documents/org" ".+\.org$")))
|
||||||
|
(setq org-agenda-files `("~/.emacs.d/config.org" ,@org-docs)))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
Also I find it really very annoying that the the current window
|
||||||
|
layout is destroyed when you run =org-agenda=. That behaviour is
|
||||||
|
changed by setting [[help:org-agenda-window-setup][org-agenda-window-setup]]:
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(setq org-agenda-window-setup 'current-window)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
Include events from my diary:
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(setq org-agenda-include-diary t)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
Though I don't like the time grid being on by default.
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(setq org-agenda-use-time-grid nil)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
I primarily use the TODO list to keep track of un-scheduled tasks,
|
||||||
|
so I don't want those displayed in there:
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(setq org-agenda-todo-ignore-scheduled t)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
Finally, I want a keybinding for the weekly agenda and global TODO
|
||||||
|
list agenda view:
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(defun org-weekly-agenda-and-todo-list ()
|
||||||
|
(interactive)
|
||||||
|
(org-agenda nil "n"))
|
||||||
|
|
||||||
|
(global-set-key (kbd "C-c a") 'org-weekly-agenda-and-todo-list)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
** Habits
|
||||||
|
Habit tracking requires the habits org module to be loaded. This is
|
||||||
|
done by adding the symbol ~'habits~ to [[help:org-modules][org-modules]], if it's not in
|
||||||
|
there already. I originally didn't have the surrounding ~unless~,
|
||||||
|
but it causes problems when re-loading the config using
|
||||||
|
[[help:org-babel-load-file][org-babel-load-file]].
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(unless (member 'habits org-modules)
|
||||||
|
(add-to-list 'org-modules 'org-habit)
|
||||||
|
(org-load-modules-maybe t))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
The [[help:org-load-modules-maybe][org-load-modules-maybe]] call forces org to load the modules in
|
||||||
|
[[help:org-modules][org-modules]]. Not sure it's needed, but I ran into some weird issues
|
||||||
|
and I think it fixed them.
|
||||||
|
|
||||||
|
The consistency graph is very nice but overlaps a lot of the habit
|
||||||
|
names, so I want to move it to the right a little:
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(setq org-habit-graph-column 42)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
Also it displays days that you did a habit in red if the habit was
|
||||||
|
overdue on that day, which makes a sort of sense, but always
|
||||||
|
showing days you did things in green makes more sense to me. The
|
||||||
|
variable [[help:org-habit-show-done-always-green][org-habit-show-done-always-green]] controls this.
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
(setq org-habit-show-done-always-green t)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
** Identation
|
||||||
Setting [[help:org-adapt-indentation][org-adapt-indentation]] to ~t~ ensures that Org will indent text
|
Setting [[help:org-adapt-indentation][org-adapt-indentation]] to ~t~ ensures that Org will indent text
|
||||||
under a headline:
|
under a headline:
|
||||||
|
|
||||||
@@ -1185,7 +1408,7 @@
|
|||||||
(setq Man-notify-method 'pushy)
|
(setq Man-notify-method 'pushy)
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
** Script-Fu
|
** Script-Fu Mode
|
||||||
GIMP has a scheme-based language -- Script-Fu -- built into it that
|
GIMP has a scheme-based language -- Script-Fu -- built into it that
|
||||||
you can use to script things (based). Sadly, the built-in console
|
you can use to script things (based). Sadly, the built-in console
|
||||||
is rather lackluster as a coding environment. Happily, there /is/
|
is rather lackluster as a coding environment. Happily, there /is/
|
||||||
@@ -1195,12 +1418,12 @@
|
|||||||
|
|
||||||
It's things like this that make me really glad I switched to Emacs
|
It's things like this that make me really glad I switched to Emacs
|
||||||
because this is ridiculously cool. By my definition of "cool"
|
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
|
I should probably extract this and make a standalone package out of
|
||||||
it and stick it on Melpa at some point.
|
it and stick it on Melpa at some point.
|
||||||
|
|
||||||
*** REPL
|
*** REPL Mode
|
||||||
The Script-Fu server request format is very simple:
|
The Script-Fu server request format is very simple:
|
||||||
|
|
||||||
| Bytes | Description |
|
| Bytes | Description |
|
||||||
@@ -1255,7 +1478,7 @@
|
|||||||
|
|
||||||
The response format is similarly simple:
|
The response format is similarly simple:
|
||||||
|
|
||||||
| Bytes | Description |
|
| Bytes | Content |
|
||||||
|-------+-----------------------------------------|
|
|-------+-----------------------------------------|
|
||||||
| 0 | 'G' magic byte (47h) |
|
| 0 | 'G' magic byte (47h) |
|
||||||
| 1 | Status code -- 0 on success, 1 on error |
|
| 1 | Status code -- 0 on success, 1 on error |
|
||||||
@@ -1312,8 +1535,8 @@
|
|||||||
(interactive)
|
(interactive)
|
||||||
(let ((buffer (get-buffer-create "*Script-Fu REPL*")))
|
(let ((buffer (get-buffer-create "*Script-Fu REPL*")))
|
||||||
(when (not (comint-check-proc buffer))
|
(when (not (comint-check-proc buffer))
|
||||||
(make-comint-in-buffer "Script-Fu REPL"
|
(make-comint-in-buffer "Script-Fu REPL" buffer
|
||||||
buffer script-fu-repl-server)
|
script-fu-repl-server)
|
||||||
(with-current-buffer buffer (script-fu-repl-mode)))
|
(with-current-buffer buffer (script-fu-repl-mode)))
|
||||||
(pop-to-buffer buffer '((display-buffer-in-direction)
|
(pop-to-buffer buffer '((display-buffer-in-direction)
|
||||||
(direction . below)
|
(direction . below)
|
||||||
@@ -1321,7 +1544,7 @@
|
|||||||
buffer))
|
buffer))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
*** Code Editing
|
*** Code Editing Mode
|
||||||
With the client stuff done, we can define the code editing mode:
|
With the client stuff done, we can define the code editing mode:
|
||||||
|
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
@@ -1329,9 +1552,7 @@
|
|||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
Now to define something to send an expression or region to the
|
Now to define something to send an expression or region to the
|
||||||
REPL. Since =script-fu-repl= returns the buffer we can use that
|
REPL:
|
||||||
to transparently start a REPL or get the existing one if one's
|
|
||||||
already running.
|
|
||||||
|
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
(defun script-fu-mode-send-region-or-sexp ()
|
(defun script-fu-mode-send-region-or-sexp ()
|
||||||
@@ -1342,19 +1563,21 @@
|
|||||||
(buffer-substring-no-properties start end))
|
(buffer-substring-no-properties start end))
|
||||||
(thing-at-point 'sexp t))))
|
(thing-at-point 'sexp t))))
|
||||||
(if (not code) (message "No code to send.")
|
(if (not code) (message "No code to send.")
|
||||||
(let* ((repl-proc (get-buffer-process (script-fu-repl))))
|
(let* ((repl-buffer (script-fu-repl))
|
||||||
|
(repl-proc (get-buffer-process repl-buffer)))
|
||||||
(script-fu-repl-send repl-proc code)))))
|
(script-fu-repl-send repl-proc code)))))
|
||||||
|
|
||||||
(define-key script-fu-mode-map (kbd "C-c C-c")
|
(define-key script-fu-mode-map (kbd "C-c C-c")
|
||||||
'script-fu-mode-send-region-or-sexp)
|
'script-fu-mode-send-region-or-sexp)
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
And finally, a similar thing for the whole file:
|
And finally a similar thing for the whole file:
|
||||||
|
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
(defun script-fu-mode-send-file ()
|
(defun script-fu-mode-send-file ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((repl-proc (get-buffer-process (script-fu-repl)))
|
(let* ((repl-buffer (script-fu-repl))
|
||||||
|
(repl-proc (get-buffer-process repl-buffer))
|
||||||
(buffer-contents
|
(buffer-contents
|
||||||
(buffer-substring-no-properties (point-min)
|
(buffer-substring-no-properties (point-min)
|
||||||
(point-max))))
|
(point-max))))
|
||||||
|
|||||||
Reference in New Issue
Block a user