From fce97628411b3ddf1d7f947c4059828fc2f9bb46 Mon Sep 17 00:00:00 2001 From: Jakob L. Kreuze Date: Sat, 2 Mar 2019 15:37:09 -0500 Subject: Reorganize Org headings --- jakob.org | 1098 +++++++++++++++++++++++++++++++------------------------------ 1 file changed, 557 insertions(+), 541 deletions(-) (limited to 'jakob.org') diff --git a/jakob.org b/jakob.org index 9c0b760..76eea24 100644 --- a/jakob.org +++ b/jakob.org @@ -1,24 +1,22 @@ -This file contains my personal Emacs configuration, done in the style of -literate programming. Of course, being myself, I have a natural tendency to go -against the grain and do everything /my/ way; rather than using the -functionality provided by =org-babel=, I've adapted a reimplementation of -=org-babel-tangle= to =eval-document= (see =init.el=), which "tangles" all of -the source blocks into a temporary buffer and proceed to evaluate that temporary -buffer. This doesn't have any noticeable implications, but it is worth noting -that there won't be a =jakob.el= in the Emacs configuration directory. +What follows is my personal configuration for GNU Emacs, done in the style of +literate programming. Literate configurations typically rely on =org-babel= to +evaluate the Lisp forms upon starting Emacs, but this configuration takes a +different approach: [[./init.el][init.el]] defines a function, =eval-document=, which "tangles" +all of the relevant Org source blocks into a temporary buffer and proceeds to +invoke =eval-buffer=. The main implication of this is that there won't be a +=jakob.el= in the Emacs configuration directory. -Custom elisp functions defined by me aren't prefixed with anything, with the -exception of functions that reimplement the functionality of existing functions. -These are prefixed with =my-= rather than replacing the original symbol, because -I imagine messing with built-in functionality in such a careless way would break -many things down the line. +Also worth noting is that there is no specific namespace (i.e. =jakob-=, =jakob/=, +or =my-=) for functions defined in this file. -* Package Management +* Bootstrapping -** straight.el +There are a few packages I use that require early initialization, which is done +under this heading. -I prefer the purely functional [[https://github.com/raxod502/straight.el][straight.el]] to =package.el=. This is not included -in vanilla Emacs, however, and requires the bootstrapping shown here. +** Package Management + +I use [[https://github.com/raxod502/straight.el][straight.el]] insetad of =package.el=. #+BEGIN_SRC elisp (defvar bootstrap-version) @@ -35,10 +33,7 @@ in vanilla Emacs, however, and requires the bootstrapping shown here. (load bootstrap-file nil 'nomessage)) #+END_SRC -** use-package - -[[https://github.com/jwiegley/use-package][use-package]], my preferred means for configuring third-party packages, -additionally requires bootstrapping. +For installation and configuration of packages, I use the [[https://github.com/jwiegley/use-package][use-package]] macro. #+BEGIN_SRC elisp (straight-use-package 'use-package) @@ -51,17 +46,38 @@ additionally requires bootstrapping. (use-package bind-key :defer t) #+END_SRC -* Libraries for Custom Elisp +** Libraries -This file is interspersed with snippets of Elisp that depend on third-party -libraries, which are loaded here to avoid the issue of symbols not being -defined. +A handful of the Elisp snippets in this file depend on third-party libraries +which aren't loaded by default. #+BEGIN_SRC elisp (require 'cl) #+END_SRC -* Vanilla Functionality +** Configuration + +Create some bindings for quickly getting to this configuration file. + +#+BEGIN_SRC elisp +(defun config-goto () + "Find the literate config file." + (interactive) + (find-file "~/.emacs.d/jakob.org")) + +(defun config-reload () + "Re-evaluate the literate config file." + (interactive) + (eval-document "~/.emacs.d/jakob.org")) + +(bind-key "C-c e" #'config-goto) +(bind-key "C-c r" #'config-reload) +#+END_SRC + +* Vanilla Emacs + +Any configuration that addresses the core of Emacs rather than a built-in or +third-party package goes here. ** Startup @@ -80,11 +96,11 @@ machines. A recurring theme in this configuration file is configuring where Emacs packages drop their various state files. =no-littering.el= is a package that handles this -with =var/= and =etc/= directories in =~/.emacs.d/=, but it's implemented in a -way that pollutes the global namespace with many variables for packages that I -don't use, and would require a significant amount of configuration on my part -for [[Gnus]] anyway, so decided to just forego it and do things my way, manually -setting these variables to subdirectories of =~/.cache= and =~/.local/share=. +with =var/= and =etc/= directories in =~/.emacs.d/=, but it's implemented in a way +that pollutes the global namespace with variables for packages that I don't use, +and would require a significant amount of configuration on my part anyway. I've +decided to manually set relevant variables to subdirectories of =~/.cache= and +=~/.local/share=. Save backup files to one directory instead of making a mess of the filesystem. @@ -119,20 +135,10 @@ massacre is not made of my =init.el=. I don't really care about persisting minibuffer history between sessions. #+BEGIN_SRC elisp -(use-package savehist - :straight nil - :config - (savehist-mode -1) -#+END_SRC - -And somehow, it still manages to run. - -#+BEGIN_SRC elisp - :init - (setq savehist-file "~/.cache/emacs/history")) +(savehist-mode -1) #+END_SRC -** Quality of Life +** User Interface Use a consistent confirmation dialog of "y or n". @@ -185,7 +191,8 @@ I like using the tab key, but prefer spaces to tabstops, and the width I prefer to use is 4 characters. #+BEGIN_SRC elisp -(setq-default indent-tabs-mode nil tab-width 4) +(setq-default indent-tabs-mode nil + tab-width 4) #+END_SRC Modern conventions state that 80 characters is the standard width. @@ -220,353 +227,140 @@ Unbind =C-z= and =C-x C-z= so I'm not accidentally calling =suspend-frame=. (global-unset-key (kbd "C-x C-z")) #+END_SRC -Create some bindings for quickly getting to this configuration file. +* Quality-of-Life +** Ivy + +As [[https://icosahedron.website/@zge/101330910258980695][suggested by a friend]], I tried out Ivy as a replacement for ido. It was love +at first sight. It's snappy, and works even better than ido after setting +=exwm-workspace-show-all-buffers= and =exwm-layout-show-all-buffers=. + +Configure how the =completing-read= is displayed. #+BEGIN_SRC elisp -(defun goto-config () - "Find the literate config file." - (interactive) - (find-file "~/.emacs.d/jakob.org")) +(use-package ivy + :init + (setq ivy-height 5) + (setq ivy-count-format "") +#+END_SRC -(defun reload-config () - "Re-evaluate the literate config file." - (interactive) - (eval-document "~/.emacs.d/jakob.org")) +Enable Ivy globally. -(bind-key "C-c e" #'goto-config) -(bind-key "C-c r" #'reload-config) +#+BEGIN_SRC elisp + :config + (ivy-mode 1) #+END_SRC -* Custom Functionality +Transformer to highlight channels in the =completing-read= of +=irc-switch-buffer= that have had activity recently. -This section is for any nontrivial Elisp functions written by me. +#+BEGIN_SRC elisp + :config + (defun irc-switch-buffer-transformer (str) + "Transform channels with activity with `ivy-virtual' face." + (let ((modified (map 'list + (lambda (channel) + (buffer-name (first channel))) + erc-modified-channels-alist))) + (if (member str modified) + (propertize str 'face 'ivy-virtual) + str))) + (ivy-set-display-transformer 'irc-switch-buffer + 'irc-switch-buffer-transformer)) +#+END_SRC -** Utilities +Use Counsel as a frontend to a couple of interactive commands. -A wrapper for =completing-read= that passes in an argument for DEF. +#+BEGIN_SRC elisp +(use-package counsel + :demand t + :bind + (("C-x b" . counsel-switch-buffer))) +#+END_SRC + +Use Swiper instead of isearch. #+BEGIN_SRC elisp -(defun completing-read-with-default (prompt collection default) - "Invoke `completing-read' with DEFAULT as the DEF argument." - (completing-read prompt collection nil nil nil nil default)) +(use-package swiper + :bind + ("C-s" . swiper)) #+END_SRC -** IRC +** Yasnippet -Convenience functions for connecting to and authenticating with my IRC bouncer. +Load all snippets when =yas-minor-mode= is enabled. #+BEGIN_SRC elisp -(defun read-bouncer-password () - "Get the password for my bouncer from authinfo" - (let ((auth (auth-source-search :host "jakob.space" :user "jakob" :port 26969))) - (unless auth - (error "No auth entry for bouncer.")) - (let ((secretf (plist-get (car auth) :secret))) - (unless secretf - (error "No secret for bouncer's auth entry.")) - (funcall secretf)))) - -(defun connect-bouncer (server) - "Connect to `SERVER' on the bouncer and rename the buffer" - (let ((password (format "%s/%s:%s" "jakob" server (read-bouncer-password)))) - (erc-tls :server "jakob.space" :port 26969 :password password) - (erc-with-buffer ((get-buffer "jakob.space:26969") - (rename-buffer server))))) +(use-package yasnippet + :demand t + :hook + (yas-minor-mode . yas-reload-all)) #+END_SRC -Convenience functions for connecting to and authenticating with an instance of -Bitlbee. +** avy #+BEGIN_SRC elisp -(defun bitlbee-connect () - "Start bitlbee as an inferior process and connect to it." - (bitlbee-start) - (erc :server "localhost" :port 6667) - (erc-with-buffer ((get-buffer "localhost:6667") - (rename-buffer "bitlbee")))) - -(defun bitlbee-identify () - "If we're on the bitlbee server, send the identify command to the - &bitlbee channel." - (when (and (string= "localhost" erc-session-server) - (string= "&bitlbee" (buffer-name))) - (erc-message "PRIVMSG" (format "%s identify %s" - (erc-default-target) - (read-bouncer-password))))) +(use-package avy + :bind + ("M-s" . avy-goto-char)) #+END_SRC -Interactive function for automatically connecting to a local Bitlbee instance -and all of the networks I have my bouncer connected to. +** Imenu + +Set up keybindings for =imenu=. #+BEGIN_SRC elisp -(defvar irc-autoconnect-networks '("bitlbee" "crtnet" "freenode" "tildetown" "tildechat") - "List of networks to automatically connect to when 'irc' is invoked.") +(use-package imenu + :bind ("C-c s" . imenu)) +#+END_SRC -(defun irc () - "Automatically connect to IRC networks." - (interactive) - (dolist (network irc-autoconnect-networks) - (if (string= network "bitlbee") - (bitlbee-connect) - (connect-bouncer network)))) +* Appearance -(defun irc-quit () - "Disconnects from and kills all buffers associated with ERC, -and ends the Bitlbee process." - (interactive) - (bitlbee-stop) - (let ((server-buffers (remove-if-not #'erc-server-buffer-p (erc-buffer-list)))) - (dolist (buffer server-buffers) - (erc-with-buffer (buffer) - (erc-quit-server (funcall erc-quit-reason nil)))))) +This feature doesn't see frequent use, but I prefer three proportionally-sized +windows to two really tiny ones over a really big one. + +#+BEGIN_SRC elisp +(setq window-combination-resize t) #+END_SRC -Interactive functions for manipulating =erc-track-exclude=. +Don't do jerky jumps when the cursor reaches the end of the window. Instead, +just scroll by one line. #+BEGIN_SRC elisp -(defvar irc-important-channels '("&bitlbee" "#tildetown" "#lobsters") - "Channels that I don't want shutting up.") - -(defun list-irc-channels () - "Returns a list of the names of the ERC channel buffers." - (map 'list #'buffer-name (remove-if #'erc-server-buffer-p (erc-buffer-list)))) +(setq scroll-conservatively most-positive-fixnum) +#+END_SRC -(defun silence-channels () - "Add all channels to `erc-track-exclude'. if they are not a -member of `irc-important-channels'." - (interactive) - (setq --old-track-exclude erc-track-exclude) - (let ((channels (list-irc-channels))) - (when (boundp 'irc-important-channels) - (dolist (channel channels) - (if (and (not (find channel irc-important-channels :test #'string=)) - (not (find channel erc-track-exclude :test #'string=))) - (push channel erc-track-exclude))))) - (setq erc-modified-channels-alist nil) - (erc-modified-channels-display)) +The menu bar can be accessed with =M-`= if I really need it, so I don't see the +point in having it take up the space at the top. The rest of these rarely see +use from me, and I'd prefer to disable them and have access to the extra screen +real estate. -(defun unsilence-channels () - "Reset the state of `erc-track-exclude'." - (interactive) - (setq erc-track-exclude - (remove-if-not #'(lambda (channel) - (find channel --old-track-exclude)) - erc-track-exclude))) +#+BEGIN_SRC elisp +(menu-bar-mode -1) +(scroll-bar-mode -1) +(tool-bar-mode -1) +(fringe-mode -1) +#+END_SRC -(defun ignore-channel () - "Use `completing-read' to ask the user for a channel to ignore." - (interactive) - (let* ((candidates (remove-if #'(lambda (channel) - (find channel erc-track-exclude)) - (list-irc-channels))) - (default (if (and (eq major-mode 'erc-mode) - (not (member (buffer-name) erc-track-exclude))) - (buffer-name))) - (channel (if default - (completing-read-with-default "Channel:" candidates default) - (completing-read "Channel: " candidates)))) - (push channel erc-track-exclude) - (erc-modified-channels-display))) +Hacking is a lot more serene when visual stimulus is kept to a minimum. -(defun unignore-channel () - "Use `completing-read' to ask the user for a channel to remove -from the list of ignored channels." - (interactive) - (let* ((candidates erc-track-exclude) - (default (if (and (eq major-mode 'erc-mode) - (member (buffer-name) erc-track-exclude)) - (buffer-name))) - (channel (if default - (completing-read-with-default "Channel:" candidates default) - (completing-read "Channel: " candidates)))) - (setq erc-track-exclude - (remove-if #'(lambda (channel) - (string= channel buffer)) - erc-track-exclude)))) +#+BEGIN_SRC elisp +(blink-cursor-mode 0) #+END_SRC -Interactive function for switching to a channel's buffer. +** Theme + +This is my custom theme, the code for which is very loosely adapted from +[[https://github.com/kuanyui/moe-theme.el][moe-theme.el]], but most of the palette has been altered to emulate the appearance +of my old setup of Emacs in a terminal emulator. #+BEGIN_SRC elisp -(defun irc-switch-buffer () - "Use `completing-read' to ask for a channel buffer to visit." - (interactive) - (let* ((candidates (list-irc-channels)) - (default (if erc-modified-channels-alist - (buffer-name (first (first erc-modified-channels-alist))))) - (channel (if default - (completing-read-with-default "Channel: " candidates default) - (completing-read "Channel: " candidates)))) - (switch-to-buffer channel))) +(deftheme chayote + "Inspired by the appearance of Emacs in my terminal emulator.") #+END_SRC -Improvements upon manually switching channel buffers. Channels can now be cycled -through interactively. - -#+BEGIN_SRC elisp -(defun bitlbee-control-buffer-p (buffer-or-name) - "Returns whether or not BUFFER-OR-NAME is connected to the -current inferior bitlbee process." - (let ((name (if (bufferp buffer-or-name) - (buffer-name buffer-or-name) - buffer-or-name))) - (and (char-equal (elt name 0) (string-to-char "&")) - (equal (erc-with-buffer ((get-buffer buffer-or-name)) - (erc-server-buffer)) - (get-buffer "bitlbee"))))) - -(defun irc-cycle-buffer-list (starting-buffer) - "Returns the forward order in which to cycle channel buffers, -which as of the current implementation is alphabetical. Control -buffers belonging to bitlbee are omitted." - (let* ((buffers (sort (map 'list - #'(lambda (channel) - (get-buffer channel)) - (list-irc-channels)) - #'(lambda (channel1 channel2) - (string< (subseq (buffer-name channel1) 1) - (subseq (buffer-name channel2) 1))))) - (split-index (position (get-buffer starting-buffer) buffers))) - (remove-if #'(lambda (buffer) (or (equal buffer (get-buffer starting-buffer)) - (bitlbee-control-buffer-p buffer))) - (if split-index - (concatenate 'list - (subseq buffers split-index) - (subseq buffers 0 split-index)) - buffers)))) - -(defun irc-cycle-forward () - "Visits the next channel buffer as dictated by -`irc-cycle-buffer-list'." - (interactive) - (switch-to-buffer (first (irc-cycle-buffer-list (current-buffer))))) - -(defun irc-cycle-backward () - "Visits the previous channel buffer as dictated by -`irc-cycle-buffer-list'." - (interactive) - (switch-to-buffer (car (last (irc-cycle-buffer-list (current-buffer)))))) -#+END_SRC - -Interactive function for marking a channel's backlog as read in ZNC. - -#+BEGIN_SRC elisp -(defun clear-irc-buffer () - "Query ZNC to clear the backlog for the current buffer." - (interactive) - (let ((channel-to-clear (buffer-name)) - (buffer (erc-query "*status" (erc-server-buffer)))) - (erc-with-buffer (buffer) - (erc-send-message (format "clearbuffer %s" channel-to-clear))))) -#+END_SRC - -Interactive function for clearing out the list of active channels in the mode -line. - -#+BEGIN_SRC elisp -(defun clear-erc-track-list () - (interactive) - (setq erc-modified-channels-alist nil) - (erc-modified-channels-display)) -#+END_SRC - -ERC tracking bar. Not mine. Shamelessly lifted from [[https://www.emacswiki.org/emacs/ErcBar][EmacsWiki]]. - -#+BEGIN_SRC elisp -(eval-after-load 'erc-track - '(progn - (defun erc-bar-move-back (n) - "Moves back n message lines. Ignores wrapping, and server messages." - (interactive "nHow many lines ? ") - (re-search-backward "^.*<.*>" nil t n)) - - (defun erc-bar-update-overlay () - "Update the overlay for current buffer, based on the content of -erc-modified-channels-alist. Should be executed on window change." - (interactive) - (let* ((info (assq (current-buffer) erc-modified-channels-alist)) - (count (cadr info))) - (if (and info (> count erc-bar-threshold)) - (save-excursion - (end-of-buffer) - (when (erc-bar-move-back count) - (let ((inhibit-field-text-motion t)) - (move-overlay erc-bar-overlay - (line-beginning-position) - (line-end-position) - (current-buffer))))) - (delete-overlay erc-bar-overlay)))) - - (defvar erc-bar-threshold 1 - "Display bar when there are more than erc-bar-threshold unread messages.") - (defvar erc-bar-overlay nil - "Overlay used to set bar") - (setq erc-bar-overlay (make-overlay 0 0)) - (overlay-put erc-bar-overlay 'face '(:underline "red")) - ;;put the hook before erc-modified-channels-update - (defadvice erc-track-mode (after erc-bar-setup-hook - (&rest args) activate) - ;;remove and add, so we know it's in the first place - (remove-hook 'window-configuration-change-hook 'erc-bar-update-overlay) - (add-hook 'window-configuration-change-hook 'erc-bar-update-overlay)) - (add-hook 'erc-send-completed-hook (lambda (str) - (erc-bar-update-overlay))))) -#+END_SRC - -* Appearance - -** Windowing - -This feature doesn't see frequent use, but I prefer three proportionally-sized -windows to two really tiny ones over a really big one. - -#+BEGIN_SRC elisp -(setq window-combination-resize t) -#+END_SRC - -** Scrolling - -Don't do jerky jumps when the cursor reaches the end of the window. Instead, -just scroll by one line. - -#+BEGIN_SRC elisp -(setq scroll-conservatively most-positive-fixnum) -#+END_SRC - -** Chrome - -The menu bar can be accessed with =M-`= if I really need it, so I don't see the -point in having it take up the space at the top. The rest of these rarely see -use from me, and I'd prefer to disable them and have access to the extra screen -real estate. - -#+BEGIN_SRC elisp -(menu-bar-mode -1) -(scroll-bar-mode -1) -(tool-bar-mode -1) -(fringe-mode -1) -#+END_SRC - -Hacking is a lot more serene when visual stimulus is kept to a minimum. - -#+BEGIN_SRC elisp -(blink-cursor-mode 0) -#+END_SRC - -** Theme - -This is my custom theme, the code for which is very loosely adapted from -[[https://github.com/kuanyui/moe-theme.el][moe-theme.el]], but most of the palette has been altered to emulate the appearance -of my old setup of Emacs in a terminal emulator. - -#+BEGIN_SRC elisp -(deftheme chayote - "Inspired by the appearance of Emacs in my terminal emulator.") -#+END_SRC - -The colors have been extracted into a variable, =palette=, and a macro, -=with-palette=, to provide access to the theme's color definitions without -significantly polluting the global namespace. +The colors have been extracted into a variable, =palette=, and a macro, +=with-palette=, to provide access to the theme's color definitions without +significantly polluting the global namespace. #+BEGIN_SRC elisp (defvar palette @@ -816,79 +610,60 @@ escaped twice -- once for =battery-format=, and once for =mode-line-format=. text)))) #+END_SRC -* Ivy - -As [[https://icosahedron.website/@zge/101330910258980695][suggested by a friend]], I tried out Ivy as a replacement for ido. It was love -at first sight. It's snappy, and works even better than ido after setting -=exwm-workspace-show-all-buffers= and =exwm-layout-show-all-buffers=. - -Configure how the =completing-read= is displayed. - -#+BEGIN_SRC elisp -(use-package ivy - :init - (setq ivy-height 5) - (setq ivy-count-format "") -#+END_SRC - -Enable Ivy globally. - -#+BEGIN_SRC elisp - :config - (ivy-mode 1) -#+END_SRC - -Transformer to highlight channels in the =completing-read= of -=irc-switch-buffer= that have had activity recently. - -#+BEGIN_SRC elisp - :config - (defun irc-switch-buffer-transformer (str) - "Transform channels with activity with `ivy-virtual' face." - (let ((modified (map 'list - (lambda (channel) - (buffer-name (first channel))) - erc-modified-channels-alist))) - (if (member str modified) - (propertize str 'face 'ivy-virtual) - str))) - (ivy-set-display-transformer 'irc-switch-buffer - 'irc-switch-buffer-transformer)) -#+END_SRC - -Use Counsel as a frontend to a couple of interactive commands. - -#+BEGIN_SRC elisp -(use-package counsel - :demand t - :bind - (("C-c k" . counsel-ag) - ("C-x b" . counsel-switch-buffer))) -#+END_SRC +** Pretty Symbols -Use Swiper instead of isearch. +Enable =prettify-symbols= globally. #+BEGIN_SRC elisp -(use-package swiper - :bind - ("C-s" . swiper) - ("C-M-s" . swiper) - ("C-r" . swiper) - ("C-M-r" . swiper)) +(global-prettify-symbols-mode t) #+END_SRC -* Yasnippet - -Load all snippets when =yas-minor-mode= is enabled. +This is snippet was taken verbatim from [[https://emacs.stackexchange.com/questions/17283/is-it-possible-to-get-prettified-symbols-in-org-mode-source-blocks][Emacs StackExchange]] to enable +=prettify-symbols= in Org source code blocks. Sadly, I can't think of a way to +implement this as advice. #+BEGIN_SRC elisp -(use-package yasnippet - :demand t - :hook - (yas-minor-mode . yas-reload-all)) +(defun org-src-font-lock-fontify-block (lang start end) + "Fontify code block. +This function is called by emacs automatic fontification, as long +as `org-src-fontify-natively' is non-nil." + (let ((lang-mode (org-src--get-lang-mode lang))) + (when (fboundp lang-mode) + (let ((string (buffer-substring-no-properties start end)) + (modified (buffer-modified-p)) + (org-buffer (current-buffer)) pos next) + (remove-text-properties start end '(face nil)) + (with-current-buffer + (get-buffer-create + (concat " org-src-fontification:" (symbol-name lang-mode))) + (delete-region (point-min) (point-max)) + (insert string " ") ;; so there's a final property change + (unless (eq major-mode lang-mode) (funcall lang-mode)) + ;; Avoid `font-lock-ensure', which does not display fonts in + ;; source block. + (font-lock-fontify-buffer) + (setq pos (point-min)) + (while (setq next (next-single-property-change pos 'face)) + (put-text-property + (+ start (1- pos)) (1- (+ start next)) 'face + (get-text-property pos 'face) org-buffer) + (setq pos next)) + ;; Addition: also copy 'composition info for prettified symbols + (setq pos (point-min)) + (while (setq next (next-single-property-change pos 'composition)) + (put-text-property + (+ start (1- pos)) (1- (+ start next)) 'composition + (get-text-property pos 'composition) org-buffer) + (setq pos next)) + ;; End addition + ) + (add-text-properties + start end + '(font-lock-fontified t fontified t font-lock-multiline t)) + (set-buffer-modified-p modified))))) #+END_SRC -* dim +** dim [[https://www.emacswiki.org/emacs/DelightedModes][Delight]] doesn't work for me, and [[https://github.com/myrjola/diminish.el][diminish]] is sadly lacking in the feature department, so I'm choosing to clean up my modeline with dim. =use-package= @@ -902,7 +677,7 @@ here. (dim-minor-name 'ivy-mode "")) #+END_SRC -* EXWM +* Window Management Yes, I use Emacs as my window manager. You should try it out some time! @@ -1039,11 +814,53 @@ pinentry's job. (setq epa-pinentry-mode 'loopback)) #+END_SRC -* Org +* System -Preference of hygene. See [[Filesystem]]. Org is also forcefully loaded because -there are a number of things declared via =:config= that I want run as soon as -Emacs starts. +** ag + +#+BEGIN_SRC elisp +(use-package ag + :bind + ("C-c k" . counsel-ag)) +#+END_SRC + +** Dired + +Hide the targets of symbolic links in dired listings. This is just a visual +preference of mine. + +#+BEGIN_SRC elisp +(use-package dired + :straight nil + :init + (setq-default dired-listing-switches "-alL")) +#+END_SRC + +** Tramp + +Preference of hygene. See [[Filesystem]]. + +#+BEGIN_SRC elisp +(use-package tramp + :straight nil + :init + (setq-default tramp-persistency-file-name "~/.cache/emacs/tramp")) +#+END_SRC + +#+BEGIN_SRC elisp +(use-package nsm + :straight nil + :init + (setq nsm-settings-file "/home/jakob/.emacs.d/network-security.data")) +#+END_SRC + +* Documents + +** Org + +Preference of hygene. See [[Filesystem]]. Org is also forcefully loaded because +there are a number of things declared via =:config= that I want run as soon as +Emacs starts. #+BEGIN_SRC elisp (use-package org @@ -1130,7 +947,7 @@ here, since =use-package= doesn't like split =:bind= declarations. ("C-c C-q" . counsel-org-tag)) #+END_SRC -** Workflow +*** Workflow Automatically open a buffer named =*Mind Dump*= to, well, save all of my thoughts. They're dated and saved in a directory so I can =ag= them. This is the @@ -1154,7 +971,7 @@ closest thing I will ever have to an implementation of =ag= for my thoughts. (rename-buffer "*Mind Dump*")) #+END_SRC -** Personal Wiki +*** Personal Wiki I maintain somewhat of a "personal wiki" using Org and I like to link between pages. This is just a convenience link type, rooted at the base of my notes @@ -1216,7 +1033,7 @@ Code for generating hierarchical category listings. (newline)))))))) #+END_SRC -** Capture +*** Capture Low-friction of adding things to the day's "mind dump" and my GTD inbox. @@ -1229,7 +1046,7 @@ Low-friction of adding things to the day's "mind dump" and my GTD inbox. "* TODO %?\n"))) #+END_SRC -** Agenda +*** Agenda Rather convoluted agenda setup to show me: - The tasks I've marked as needing to be done today. @@ -1287,7 +1104,7 @@ Rather convoluted agenda setup to show me: ((org-agenda-compact-blocks t)))))) #+END_SRC -** Drill +*** Drill Scan the directory of the current buffer's file for other items -- this is so that I can spread my cards across multiple files and still be tested on all of @@ -1307,27 +1124,27 @@ items right on the first try. It's unhelpful and really just annoying. (setq org-drill-forgetting-index 100)) #+END_SRC -* Elfeed - -Preference of hygene. See [[Filesystem]]. +*** Blog #+BEGIN_SRC elisp -(use-package elfeed - :init - (setq elfeed-db-directory "~/.local/share/elfeed")) +;; (use-package ox-hugo +;; :straight nil) #+END_SRC -Configure Elfeed to sync with the instance of Tiny Tiny RSS I use. +** pdf-tools + +doc-view= is unbearable for reading PDF's of any considerable size and +=pdf-tools= brings a number of significant improvements, so I can justify not +using the built-in solution. Even though I can run MuPDF in an [[EXWM]] buffer, the +integration in terms of searching and viewing attachments that comes with +=pdf-tools= makes for a much more pleasant experience. #+BEGIN_SRC elisp -(use-package elfeed-protocol +(use-package pdf-tools :config - (setq elfeed-feeds (list (list "ttrss+https://jakob@rss.tildeverse.org" - :use-authinfo t))) - (elfeed-protocol-enable)) + (pdf-loader-install)) #+END_SRC - -* ERC +* IRC Only load the modules I actually use. This list deviates from the default by including =truncate=, but omitting =autojoin=. @@ -1541,117 +1358,24 @@ Ensure a package for starting an instance of Bitlbee. (setq bitlbee-user-directory "~/.config/bitlbee/")) #+END_SRC -* pdf-tools +* RSS -=doc-view= is unbearable for reading PDF's of any considerable size and -=pdf-tools= brings a number of significant improvements, so I can justify not -using the built-in solution. Even though I can run MuPDF in an [[EXWM]] buffer, the -integration in terms of searching and viewing attachments that comes with -=pdf-tools= makes for a much more pleasant experience. - -#+BEGIN_SRC elisp -(use-package pdf-tools - :config - (pdf-loader-install)) -#+END_SRC - -* ag - -#+BEGIN_SRC elisp -(use-package ag) -#+END_SRC - -* avy - -#+BEGIN_SRC elisp -(use-package avy - :bind - ("M-s" . avy-goto-char)) -#+END_SRC - -* Pretty Symbols - -Enable =prettify-symbols= globally. - -#+BEGIN_SRC elisp -(global-prettify-symbols-mode t) -#+END_SRC - -This is snippet was taken verbatim from [[https://emacs.stackexchange.com/questions/17283/is-it-possible-to-get-prettified-symbols-in-org-mode-source-blocks][Emacs StackExchange]] to enable -=prettify-symbols= in Org source code blocks. Sadly, I can't think of a way to -implement this as advice. - -#+BEGIN_SRC elisp -(defun org-src-font-lock-fontify-block (lang start end) - "Fontify code block. -This function is called by emacs automatic fontification, as long -as `org-src-fontify-natively' is non-nil." - (let ((lang-mode (org-src--get-lang-mode lang))) - (when (fboundp lang-mode) - (let ((string (buffer-substring-no-properties start end)) - (modified (buffer-modified-p)) - (org-buffer (current-buffer)) pos next) - (remove-text-properties start end '(face nil)) - (with-current-buffer - (get-buffer-create - (concat " org-src-fontification:" (symbol-name lang-mode))) - (delete-region (point-min) (point-max)) - (insert string " ") ;; so there's a final property change - (unless (eq major-mode lang-mode) (funcall lang-mode)) - ;; Avoid `font-lock-ensure', which does not display fonts in - ;; source block. - (font-lock-fontify-buffer) - (setq pos (point-min)) - (while (setq next (next-single-property-change pos 'face)) - (put-text-property - (+ start (1- pos)) (1- (+ start next)) 'face - (get-text-property pos 'face) org-buffer) - (setq pos next)) - ;; Addition: also copy 'composition info for prettified symbols - (setq pos (point-min)) - (while (setq next (next-single-property-change pos 'composition)) - (put-text-property - (+ start (1- pos)) (1- (+ start next)) 'composition - (get-text-property pos 'composition) org-buffer) - (setq pos next)) - ;; End addition - ) - (add-text-properties - start end - '(font-lock-fontified t fontified t font-lock-multiline t)) - (set-buffer-modified-p modified))))) -#+END_SRC - -* Dired - -Hide the targets of symbolic links in dired listings. This is just a visual -preference of mine. +Preference of hygene. See [[Filesystem]]. #+BEGIN_SRC elisp -(use-package dired - :straight nil +(use-package elfeed :init - (setq-default dired-listing-switches "-alL")) -#+END_SRC - -* Imenu - -Set up keybindings for =imenu=. - -#+BEGIN_SRC elisp -(use-package imenu - :bind ("C-c s" . imenu)) + (setq elfeed-db-directory "~/.local/share/elfeed")) #+END_SRC -* Tramp - -Preference of hygene. See [[Filesystem]]. +Configure Elfeed to sync with the instance of Tiny Tiny RSS I use. #+BEGIN_SRC elisp -(use-package tramp - :straight nil - :init - (setq-default tramp-persistency-file-name "~/.cache/emacs/tramp")) +(use-package elfeed-protocol + :config + (setq elfeed-feeds (list (list "ttrss+https://jakob@rss.tildeverse.org" + :use-authinfo t))) + (elfeed-protocol-enable)) #+END_SRC * Programming Tools @@ -1736,6 +1460,21 @@ don't care about the output unless there were errors. :bind ("C-c g" . magit-status)) #+END_SRC +** Projectile + +#+BEGIN_SRC elisp +(use-package projectile + :demand t + + :init + (setq projectile-completion-system 'ivy) + (setq projectile-known-projects-file "~/.local/share/projectile-bookmarks.eld") + + :bind + ("C-c C-x C-f" . projectile-find-file) + ("C-c C-x C-p" . projectile-switch-project)) +#+END_SRC + * Programming Languages ** Language Server Protocol @@ -1750,6 +1489,7 @@ machinery. (setq lsp-prefer-flymake nil) (setq lsp-enable-xref t) (setq lsp-session-file "~/.cache/emacs/.lsp-session-v1") + (setq lsp-auto-guess-root t) :bind (:map lsp-mode-map @@ -1939,3 +1679,279 @@ Use a [[Language Server Protocol]] daemon. :init (setq-default js-indent-level 2)) #+END_SRC + +* Custom Functionality + +This section is for any nontrivial Elisp functions written by me. + +** Utilities + +A wrapper for =completing-read= that passes in an argument for DEF. + +#+BEGIN_SRC elisp +(defun completing-read-with-default (prompt collection default) + "Invoke `completing-read' with DEFAULT as the DEF argument." + (completing-read prompt collection nil nil nil nil default)) +#+END_SRC + +** IRC + +Convenience functions for connecting to and authenticating with my IRC bouncer. + +#+BEGIN_SRC elisp +(defun read-bouncer-password () + "Get the password for my bouncer from authinfo" + (let ((auth (auth-source-search :host "jakob.space" :user "jakob" :port 26969))) + (unless auth + (error "No auth entry for bouncer.")) + (let ((secretf (plist-get (car auth) :secret))) + (unless secretf + (error "No secret for bouncer's auth entry.")) + (funcall secretf)))) + +(defun connect-bouncer (server) + "Connect to `SERVER' on the bouncer and rename the buffer" + (let ((password (format "%s/%s:%s" "jakob" server (read-bouncer-password)))) + (erc-tls :server "jakob.space" :port 26969 :password password) + (erc-with-buffer ((get-buffer "jakob.space:26969") + (rename-buffer server))))) +#+END_SRC + +Convenience functions for connecting to and authenticating with an instance of +Bitlbee. + +#+BEGIN_SRC elisp +(defun bitlbee-connect () + "Start bitlbee as an inferior process and connect to it." + (bitlbee-start) + (erc :server "localhost" :port 6667) + (erc-with-buffer ((get-buffer "localhost:6667") + (rename-buffer "bitlbee")))) + +(defun bitlbee-identify () + "If we're on the bitlbee server, send the identify command to the + &bitlbee channel." + (when (and (string= "localhost" erc-session-server) + (string= "&bitlbee" (buffer-name))) + (erc-message "PRIVMSG" (format "%s identify %s" + (erc-default-target) + (read-bouncer-password))))) +#+END_SRC + +Interactive function for automatically connecting to a local Bitlbee instance +and all of the networks I have my bouncer connected to. + +#+BEGIN_SRC elisp +(defvar irc-autoconnect-networks '("bitlbee" "crtnet" "freenode" "tildetown" "tildechat") + "List of networks to automatically connect to when 'irc' is invoked.") + +(defun irc () + "Automatically connect to IRC networks." + (interactive) + (dolist (network irc-autoconnect-networks) + (if (string= network "bitlbee") + (bitlbee-connect) + (connect-bouncer network)))) + +(defun irc-quit () + "Disconnects from and kills all buffers associated with ERC, +and ends the Bitlbee process." + (interactive) + (bitlbee-stop) + (let ((server-buffers (remove-if-not #'erc-server-buffer-p (erc-buffer-list)))) + (dolist (buffer server-buffers) + (erc-with-buffer (buffer) + (erc-quit-server (funcall erc-quit-reason nil)))))) +#+END_SRC + +Interactive functions for manipulating =erc-track-exclude=. + +#+BEGIN_SRC elisp +(defvar irc-important-channels '("&bitlbee" "#tildetown" "#lobsters") + "Channels that I don't want shutting up.") + +(defun list-irc-channels () + "Returns a list of the names of the ERC channel buffers." + (map 'list #'buffer-name (remove-if #'erc-server-buffer-p (erc-buffer-list)))) + +(defun silence-channels () + "Add all channels to `erc-track-exclude'. if they are not a +member of `irc-important-channels'." + (interactive) + (setq --old-track-exclude erc-track-exclude) + (let ((channels (list-irc-channels))) + (when (boundp 'irc-important-channels) + (dolist (channel channels) + (if (and (not (find channel irc-important-channels :test #'string=)) + (not (find channel erc-track-exclude :test #'string=))) + (push channel erc-track-exclude))))) + (setq erc-modified-channels-alist nil) + (erc-modified-channels-display)) + +(defun unsilence-channels () + "Reset the state of `erc-track-exclude'." + (interactive) + (setq erc-track-exclude + (remove-if-not #'(lambda (channel) + (find channel --old-track-exclude)) + erc-track-exclude))) + +(defun ignore-channel () + "Use `completing-read' to ask the user for a channel to ignore." + (interactive) + (let* ((candidates (remove-if #'(lambda (channel) + (find channel erc-track-exclude)) + (list-irc-channels))) + (default (if (and (eq major-mode 'erc-mode) + (not (member (buffer-name) erc-track-exclude))) + (buffer-name))) + (channel (if default + (completing-read-with-default "Channel:" candidates default) + (completing-read "Channel: " candidates)))) + (push channel erc-track-exclude) + (erc-modified-channels-display))) + +(defun unignore-channel () + "Use `completing-read' to ask the user for a channel to remove +from the list of ignored channels." + (interactive) + (let* ((candidates erc-track-exclude) + (default (if (and (eq major-mode 'erc-mode) + (member (buffer-name) erc-track-exclude)) + (buffer-name))) + (channel (if default + (completing-read-with-default "Channel:" candidates default) + (completing-read "Channel: " candidates)))) + (setq erc-track-exclude + (remove-if #'(lambda (channel) + (string= channel buffer)) + erc-track-exclude)))) +#+END_SRC + +Interactive function for switching to a channel's buffer. + +#+BEGIN_SRC elisp +(defun irc-switch-buffer () + "Use `completing-read' to ask for a channel buffer to visit." + (interactive) + (let* ((candidates (list-irc-channels)) + (default (if erc-modified-channels-alist + (buffer-name (first (first erc-modified-channels-alist))))) + (channel (if default + (completing-read-with-default "Channel: " candidates default) + (completing-read "Channel: " candidates)))) + (switch-to-buffer channel))) +#+END_SRC + +Improvements upon manually switching channel buffers. Channels can now be cycled +through interactively. + +#+BEGIN_SRC elisp +(defun bitlbee-control-buffer-p (buffer-or-name) + "Returns whether or not BUFFER-OR-NAME is connected to the +current inferior bitlbee process." + (let ((name (if (bufferp buffer-or-name) + (buffer-name buffer-or-name) + buffer-or-name))) + (and (char-equal (elt name 0) (string-to-char "&")) + (equal (erc-with-buffer ((get-buffer buffer-or-name)) + (erc-server-buffer)) + (get-buffer "bitlbee"))))) + +(defun irc-cycle-buffer-list (starting-buffer) + "Returns the forward order in which to cycle channel buffers, +which as of the current implementation is alphabetical. Control +buffers belonging to bitlbee are omitted." + (let* ((buffers (sort (map 'list + #'(lambda (channel) + (get-buffer channel)) + (list-irc-channels)) + #'(lambda (channel1 channel2) + (string< (subseq (buffer-name channel1) 1) + (subseq (buffer-name channel2) 1))))) + (split-index (position (get-buffer starting-buffer) buffers))) + (remove-if #'(lambda (buffer) (or (equal buffer (get-buffer starting-buffer)) + (bitlbee-control-buffer-p buffer))) + (if split-index + (concatenate 'list + (subseq buffers split-index) + (subseq buffers 0 split-index)) + buffers)))) + +(defun irc-cycle-forward () + "Visits the next channel buffer as dictated by +`irc-cycle-buffer-list'." + (interactive) + (switch-to-buffer (first (irc-cycle-buffer-list (current-buffer))))) + +(defun irc-cycle-backward () + "Visits the previous channel buffer as dictated by +`irc-cycle-buffer-list'." + (interactive) + (switch-to-buffer (car (last (irc-cycle-buffer-list (current-buffer)))))) +#+END_SRC + +Interactive function for marking a channel's backlog as read in ZNC. + +#+BEGIN_SRC elisp +(defun clear-irc-buffer () + "Query ZNC to clear the backlog for the current buffer." + (interactive) + (let ((channel-to-clear (buffer-name)) + (buffer (erc-query "*status" (erc-server-buffer)))) + (erc-with-buffer (buffer) + (erc-send-message (format "clearbuffer %s" channel-to-clear))))) +#+END_SRC + +Interactive function for clearing out the list of active channels in the mode +line. + +#+BEGIN_SRC elisp +(defun clear-erc-track-list () + (interactive) + (setq erc-modified-channels-alist nil) + (erc-modified-channels-display)) +#+END_SRC + +ERC tracking bar. Not mine. Shamelessly lifted from [[https://www.emacswiki.org/emacs/ErcBar][EmacsWiki]]. + +#+BEGIN_SRC elisp +(eval-after-load 'erc-track + '(progn + (defun erc-bar-move-back (n) + "Moves back n message lines. Ignores wrapping, and server messages." + (interactive "nHow many lines ? ") + (re-search-backward "^.*<.*>" nil t n)) + + (defun erc-bar-update-overlay () + "Update the overlay for current buffer, based on the content of +erc-modified-channels-alist. Should be executed on window change." + (interactive) + (let* ((info (assq (current-buffer) erc-modified-channels-alist)) + (count (cadr info))) + (if (and info (> count erc-bar-threshold)) + (save-excursion + (end-of-buffer) + (when (erc-bar-move-back count) + (let ((inhibit-field-text-motion t)) + (move-overlay erc-bar-overlay + (line-beginning-position) + (line-end-position) + (current-buffer))))) + (delete-overlay erc-bar-overlay)))) + + (defvar erc-bar-threshold 1 + "Display bar when there are more than erc-bar-threshold unread messages.") + (defvar erc-bar-overlay nil + "Overlay used to set bar") + (setq erc-bar-overlay (make-overlay 0 0)) + (overlay-put erc-bar-overlay 'face '(:underline "red")) + ;;put the hook before erc-modified-channels-update + (defadvice erc-track-mode (after erc-bar-setup-hook + (&rest args) activate) + ;;remove and add, so we know it's in the first place + (remove-hook 'window-configuration-change-hook 'erc-bar-update-overlay) + (add-hook 'window-configuration-change-hook 'erc-bar-update-overlay)) + (add-hook 'erc-send-completed-hook (lambda (str) + (erc-bar-update-overlay))))) +#+END_SRC -- cgit v1.3