Switch to literate config

master
trémeur 2 years ago
parent a10d99075d
commit fbeb232c08

@ -0,0 +1,789 @@
* =$whoami=, a big neckbeard, thats who
Set basic information, false-online-pseudonym-of-a-name, approximate location.
#+BEGIN_SRC emacs-lisp
(setq user-mail-address "eheu48@gmail.com")
(setq user-full-name "Trémeur Karahés")
(setq calendar-latitude 54.59)
(setq calendar-longitude -5.88)
(setq calendar-location-name "Belfast")
#+END_SRC
* Systems
Define functions that specify what OS Im on, also whether Im at work or not. Then I can implement specific packages according to need/compatibility.
#+BEGIN_SRC emacs-lisp
(defun islin ()
"Return true if on linux"
(string-equal system-type "gnu/linux")
)
(defun iswin ()
"Return true if on windows"
(string-equal system-type "windows-nt")
)
(defun ismac ()
"Return true if on macos"
(string-equal system-type "darwin")
)
(defun atwork ()
"Return true if at work"
(string-equal user-login-name "3055822")
)
#+END_SRC
* It's not 1986
Set everything to UTF-8. I use accented characters regularly.
#+BEGIN_SRC emacs-lisp
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-language-environment 'utf-8)
(unless (iswin) (set-selection-coding-system 'utf-8))
(when (iswin) (set-selection-coding-system 'utf-16-le))
#+END_SRC
* Sonic arts
Stop Emacs making sounds. I dont think it ever made sounds before, but everyone is very insistent about the need to stop Emacs making sounds.
#+BEGIN_SRC emacs-lisp
(setq ring-bell-function 'ignore)
(setq visible-bell t)
#+END_SRC
Also suppress certain warnings that would otherwise come up all the time and contribute very little to the experience.
#+BEGIN_SRC emacs-lisp
(setq ad-redefinition-action 'accept)
(setq python-indent-guess-indent-offset-verbose nil)
(setq byte-compile-warnings '(cl-functions))
#+END_SRC
* =use-package=
Set up package handling, including =use-package=. Some of the =org= tools I use are from Non-GNU ELPA, I think. Most of this is the standard =use-package= setup stuff.
#+BEGIN_SRC emacs-lisp
(package-initialize)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives '("nongnu" . "https://elpa.nongnu.org/nongnu/"))
(setq package-check-signature nil)
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(require 'use-package-ensure)
(setq use-package-always-ensure t)
#+END_SRC
* Miscellaneous changes to make to the basic config
Firstly, I dont want finding files to be case-sensitive, same as in =zsh=:
#+BEGIN_SRC emacs-lisp
(setq completion-ignore-case t)
(setq read-file-name-completion-ignore-case t)
(setq read-buffer-completion-ignore-case t)
#+END_SRC
Make the +window+ /frame/ look nice and clean. Scroll bars behave pointlessly on Windows anyway. Not hiding the menu bar because Im not quite that leet yet. One day …
#+BEGIN_SRC emacs-lisp
(setq inhibit-startup-screen t)
(tool-bar-mode -1)
(scroll-bar-mode -1)
#+END_SRC
Stop creating all those =~= files everywhere. Put them somewhere that I can ignore them.
#+BEGIN_SRC emacs-lisp
(setq backup-directory-alist '(("." . "~/.emacs.d/backups")))
#+END_SRC
This gives buffers sensible names.
#+BEGIN_SRC emacs-lisp
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)
#+END_SRC
Turn on automatic bracket/quotation mark matching.
#+BEGIN_SRC emacs-lisp
(electric-pair-mode 1)
#+END_SRC
Stop =init.el= getting forcibly appended with package information.
#+BEGIN_SRC emacs-lisp
(defun package--save-selected-packages (&rest opt) nil)
#+END_SRC
SOMETIMES I WANT TO UPCASE OR DOWNCASE AN ENTIRE REGION, WHAT OF IT.
#+BEGIN_SRC emacs-lisp
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
#+END_SRC
Its 2022.
#+BEGIN_SRC emacs-lisp
(setq python-shell-interpreter "python3")
#+END_SRC
** OS-specific stuff
On Linux, I have to tell Emacs to use Chrome for web links.
#+BEGIN_SRC emacs-lisp
(when (islin)
(setq browse-url-browser-function 'browse-url-generic
browse-url-generic-program "google-chrome"
))
#+END_SRC
Honestly I dont know if Ill ever use macOS again, but in case I do, I need the meta key to work.
#+BEGIN_SRC emacs-lisp
(when (ismac)
(setq ns-alternate-modifier 'meta)
(setq ns-right-alternate-modifier 'none))
#+END_SRC
Windows likes to set the default directory to the folder where the Emacs binary is stored, which it probably thinks is helpful, but is in fact Very Stupid.
#+BEGIN_SRC emacs-lisp
(when (iswin)
(setq default-directory "~/"))
#+END_SRC
* Packages, modes, etc.
** =bibtex=
I use BibLaTeX for better compatibility with accented characters and generally being more sensible.
#+BEGIN_SRC
(use-package bibtex
:mode ("\\.bib" . bibtex-mode)
:config
(setq bibtex-dialect 'biblatex))
#+END_SRC
** =calibredb=
This may work only on Linux (it uses SQL???, but my ebooks are only on Linux so thats ok.
#+BEGIN_SRC emacs-lisp
(when (islin)
(use-package calibredb
:defer t
:config
(setq calibredb-root-dir "~/Documents/drive/calibre/ebooks")
(setq calibredb-db-dir (expand-file-name "metadata.db" calibredb-root-dir))
(setq calibredb-library-alist '(("~/Documents/drive/calibre/ebooks")
("~/Documents/drive/calibre/ffff")
("~/Documents/drive/calibre/ovely")))
(setq calibredb-sort-by 'author)
(setq calibredb-order 'asc)))
#+END_SRC
** =deft=
Let me search my journal files, not synced to my work computer. Stupid regexp for excluding full-year files so it only displays the per-day ones.
#+BEGIN_SRC emacs-lisp
(unless (atwork)
(use-package deft
;; for searching journal files
:config
(setq deft-extensions '("org"))
(setq deft-directory "~/Documents/drive/org/journal")
(setq deft-ignore-file-regexp ".*[0-9][0-9][0-9][0-9]\.org")
(setq deft-current-sort-method 'title)
(setq deft-recursive t)))
#+END_SRC
** =dimmer=
Dims inactive buffers.
#+BEGIN_SRC emacs-lisp
(use-package dimmer
:init
(dimmer-mode t)
:config
(setq dimmer-fraction 0.4))
#+END_SRC
** =doom-modeline=
Much nicer-looking modeline, and still my favourite over newer, trendier options. Last time I tried installing this from MELPA it made Emacs crash; I dont know if this is fixed yet.
#+BEGIN_SRC emacs-lisp
(use-package doom-modeline
:init
(doom-modeline-mode 1)
:config
(setq doom-modeline-buffer-file-name-style 'buffer-name)
(setq doom-modeline-minor-modes t)
(setq doom-modeline-enable-word-count t)
(setq doom-modeline-continuous-word-count-modes '(markdown-mode gfm-mode))
(setq doom-modeline-buffer-encoding nil))
#+END_SRC
** =elfeed=
Obviously I use an org file to manage my feeds.
#+BEGIN_SRC emacs-lisp
(use-package elfeed-org
:config
(elfeed-org)
(setq rmh-elfeed-org-files (list "~/Documents/drive/org/feeds.org")))
#+END_SRC
Standard Elfeed settings:
#+BEGIN_SRC emacs-lisp
(defun elfeed-load-db-and-open ()
"Wrapper to load the elfeed db from disk before opening"
(interactive)
(elfeed-db-load)
(elfeed)
(elfeed-search-update--force)
(elfeed-update))
(global-set-key (kbd "C-x w") 'elfeed-load-db-and-open)
(defalias 'elfeed-toggle-star
(elfeed-expose #'elfeed-search-toggle-all 'star))
(eval-after-load 'elfeed-search
'(define-key elfeed-search-mode-map (kbd "m") 'elfeed-toggle-star))
(defun elfeed-save-db-and-bury ()
"Wrapper to save the elfeed db to disk before burying buffer"
(interactive)
(elfeed-db-save)
(quit-window))
(use-package elfeed
:bind (:map elfeed-search-mode-map
("q" . elfeed-save-db-and-bury))
:custom
(elfeed-sort-order 'ascending)
(elfeed-db-directory "~/Documents/drive/org/elfeed"))
#+END_SRC
I am a huge supporter of big-endian date formats.
#+BEGIN_SRC emacs-lisp
(defun elfeed-search-format-date (date)
(format-time-string "%Y-%m-%d %H:%M" (seconds-to-time date)))
#+END_SRC
This apparently deletes really old entries from the database.
#+BEGIN_SRC emacs-lisp
(add-hook 'elfeed-new-entry-hook
(elfeed-make-tagger :before "6 months ago"
:remove 'unread))
#+END_SRC
** =git-gutter=
Shows, or at least purports to show, git diff in the left margin if the file is being tracked by git.
#+BEGIN_SRC emacs-lisp
(use-package git-gutter
:config
(global-git-gutter-mode 1)
(set-face-foreground 'git-gutter:added "forest green")
(set-face-foreground 'git-gutter:modified "goldenrod")
(set-face-foreground 'git-gutter:deleted "brown")
(setq git-gutter:added-sign "+"
git-gutter:modified-sign "×"
git-gutter:deleted-sign "-"))
#+END_SRC
** =lastfm=
This works only for =emacs27= and above, and I dont want to use it at work, so heres a nested =unless= in case my emacs version ever gets updated there.
#+BEGIN_SRC emacs-lisp
(unless (version< emacs-version "27")
(unless (atwork)
(use-package lastfm)))
#+END_SRC
** =markdown-mode=
I kind of hate markdown but I still have to use it sometimes.
#+BEGIN_SRC emacs-lisp
(use-package markdown-mode
:mode (("README\\.md\\'" . gfm-mode)
("\\.md\\'" . markdown-mode)
("\\.markdown\\'" . markdown-mode))
:init
(add-hook 'markdown-mode-hook 'auto-fill-mode)
(add-hook 'markdown-mode-hook 'typo-mode)
:config
(setq markdown-asymmetric-header t)
:custom
(markdown-header-scaling t)
:custom-face
(markdown-header-face ((t (:inherit (default font-lock-function-name-face) :weight bold)))))
#+END_SRC
** =minions=
Lists minor modes in a menu.
#+BEGIN_SRC emacs-lisp
(use-package minions
:config
(minions-mode))
#+END_SRC
** =mu4e=
I really only use this for DW posts, but Im constantly surprised by how well it works. This package is the reason I cant upgrade to emacs28, because it doesnt currently seem to work; also, it uses =cl=, which is deprecated, hence suppressing warnings about it above.
#+BEGIN_SRC emacs-lisp
(when (islin)
(add-to-list 'load-path "/usr/share/emacs/site-lisp/mu4e")
(load-file "~/.emacs.d/mail.el")
(require 'mu4e)
(setq send-mail-function 'smtpmail-send-it))
#+END_SRC
** =neotree=
Show a nice filetree with icons. I use this much less often than I should.
#+BEGIN_SRC emacs-lisp
(use-package neotree
;; show filetree
:init
(global-set-key [f8] 'neotree-toggle)
:config
(setq neo-theme (if (display-graphic-p) 'icons 'arrow)))
#+END_SRC
** =nov=
For reading ebooks. Only on Linux because I (supposedly) use it with my calibre library.
#+BEGIN_SRC emacs-lisp
(when (islin)
(use-package nov
:init
(add-to-list 'auto-mode-alist '("\\.epub\\'" . nov-mode)))
(defun my-nov-font-setup ()
(face-remap-add-relative 'variable-pitch :family "Liberation Serif"
:height 2.0))
(add-hook 'nov-mode-hook 'my-nov-font-setup))
#+END_SRC
** =org-mode= my love
*** Initial settings
I want to indent under headings, I dont want pointless line breaks when text can just wrap sensibly in the window, and I want to be able to ignore asterisks etc. when I skip to the beginning of lines.
#+BEGIN_SRC emacs-lisp
(add-hook 'org-mode-hook 'org-indent-mode)
(add-hook 'org-mode-hook 'visual-line-mode)
(setq org-special-ctrl-a/e t)
#+END_SRC
Display images in org buffers. Ive increased the width to 500px because 300 was quite small.
#+BEGIN_SRC emacs-lisp
(setq org-display-inline-images t)
(setq org-redisplay-inline-images t)
(setq org-startup-with-inline-images "inlineimages")
(setq org-image-actual-width '(500))
#+END_SRC
Load the common agenda settings, i.e. those that I use in conky as well.
#+BEGIN_SRC emacs-lisp
(load-file "~/.emacs.d/agenda-common.el")
#+END_SRC
Set general TODO keywords.
#+BEGIN_SRC emacs-lisp
(setq org-todo-keywords
'((sequence "TODO" "|" "DONE" "CANCELLED")))
#+END_SRC
In emacs27 and above, I can set certain headlines not to be exported. I havent used this yet but it sounds useful.
#+BEGIN_SRC emacs-lisp
(unless (version< emacs-version "27")
(use-package org-contrib)
(require 'ox-extra)
(ox-extras-activate '(ignore-headlines)))
#+END_SRC
Settings for export, fairly basic because the only thing I regularly export is HTML DW post previews.
#+BEGIN_SRC emacs-lisp
(setq org-export-headline-levels 6)
(setq org-html-head-include-default-style nil)
(setq org-html-head "<link rel=\"stylesheet\" type=\"text/css\" href=\"https://tre.praze.net/fic/fic2.css\" />")
#+END_SRC
*** Packages
**** =org-agenda-property=
Let properties be inherited by subheadings. I use this a lot for =:LOCATION:= on recurring events.
#+BEGIN_SRC emacs-lisp
(use-package org-agenda-property)
;; lets properties inherit
#+END_SRC
**** =org-journal=
Automate a tiny part of something I was previously doing manually.
#+BEGIN_SRC emacs-lisp
(unless (atwork)
(defun org-journal-file-header-func (time)
(concat "<" (format-time-string "%Y-%m-%d %a") ">\n\n"))
(use-package org-journal
:bind ("C-c j" . org-journal-new-entry)
:config
(setq org-journal-dir "~/Documents/drive/org/journal")
(setq org-journal-file-format "%Y/%m/%Y-%m-%d.org")
(setq org-journal-find-file 'find-file)
(setq org-journal-date-format "journal")
(setq org-journal-time-format "%H:%M\n")
(setq org-journal-file-header 'org-journal-file-header-func)))
#+END_SRC
**** =org-modern=/=org-bullets=
Use =org-modern= on emacs27 and above (although Im still not wild about it), =org-bullets= otherwise.
#+BEGIN_SRC emacs-lisp
(unless (version< emacs-version "27")
(use-package org-modern
:hook
(org-mode . org-modern-mode)))
(if (version< emacs-version "27")
(use-package org-bullets
:custom
(org-bullets-bullet-list '("✸"))
(org-ellipsis " ⤵")
:hook (org-mode . org-bullets-mode)))
#+END_SRC
**** =org-noter=
RIP =interleave=, but this does ok as a replacement.
#+BEGIN_SRC emacs-lisp
(use-package org-noter
:config
(setq org-noter-property-doc-file "INTERLEAVE_PDF"
org-noter-property-note-location "INTERLEAVE_PAGE_NOTE"))
#+END_SRC
**** =org-sidebar=
Display the file outline in a sidebar.
#+BEGIN_SRC emacs-lisp
(unless (version< emacs-version "27")
(use-package org-sidebar
:bind ("C-c C-x s" . org-sidebar-tree)))
#+END_SRC
**** =org-wc=
Display word counts next to org headings.
#+BEGIN_SRC emacs-lisp
(unless (version< emacs-version "27")
(use-package org-wc
:bind ("C-c C-x w" . org-wc-display)))
#+END_SRC
*** Agenda settings
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-c a") 'org-agenda)
(setq calendar-week-start-day 1)
(setq org-agenda-start-on-weekday nil)
#+END_SRC
Set the files to be included.
#+BEGIN_SRC emacs-lisp
(unless (atwork)
(setq org-agenda-files (list "~/Documents/drive/org/calendar"
"~/Documents/drive/org/period.org"
"~/Documents/drive/org/habit.org")))
(when (atwork)
(setq org-agenda-files (list "~/Documents/drive/org/calendar"
"~/Documents/drive/org/period.org"
"~/Documents/drive/org/acwri.org")))
#+END_SRC
Set how the agenda looks.
#+BEGIN_SRC emacs-lisp
(setq org-agenda-prefix-format
'((todo . "%-2c %b")
(tags . "%-2c %b")
(agenda . "%-2c %?-12t%?-12s")))
(setq org-use-property-inheritance (quote ("LOCATION")))
(setq org-agenda-todo-ignore-scheduled t)
(setq org-agenda-todo-ignore-deadlines t)
#+END_SRC
Use a horizontal line to divide each day from the next.
#+BEGIN_SRC emacs-lisp
(setq org-agenda-format-date (lambda (date) (concat "\n"
(make-string (window-width) 9472)
"\n"
(org-agenda-format-date-aligned date))))
#+END_SRC
Set up habit display.
#+BEGIN_SRC emacs-lisp
(add-to-list 'org-modules 'org-habit t)
(setq org-habit-show-all-today t)
#+END_SRC
** =paren=
Highlights matching bracket.
#+BEGIN_SRC emacs-lisp
(use-package paren
:config
(show-paren-mode +1))
#+END_SRC
** =pdf-tools=/=doc-view=
Use the superior package for viewing PDFs on the superior operating system, and use a less reliable one otherwise. Ghostscript has to be installed on Windows, but its indispensable anyway.
#+BEGIN_SRC emacs-lisp
(unless (iswin) (use-package pdf-tools
:config
(pdf-tools-install)
(define-key pdf-view-mode-map (kbd "C-s") 'isearch-forward)
(add-hook 'pdf-view-mode-hook (lambda () (cua-mode 0)))
(setq pdf-view-resize-factor 1.1)))
(when (iswin) (use-package doc-view
:config
(setq doc-view-ghostscript-program "gswin32c")))
#+END_SRC
** =rainbow-mode=
Adds visual indication of colours to CSS files.
#+BEGIN_SRC emacs-lisp
(use-package rainbow-mode
:hook
(css-mode . rainbow-mode))
#+END_SRC
** =recentf=
Gives me a dialog with recently opened files. Package management/elfeed stuff has to be manually excluded for obvious reasons. Surely I dont have to call =add-to-list= separately every time, but I havent found a more sensible way of doing it.
#+BEGIN_SRC emacs-lisp
(use-package recentf
:config
(recentf-mode 1)
(setq recentf-max-menu-items 20)
(setq recentf-max-saved-items 20)
(global-set-key "\C-x\ \C-r" 'recentf-open-files)
(add-to-list 'recentf-exclude
(expand-file-name "~/.emacs.d/elpa/*"))
(add-to-list 'recentf-exclude
(expand-file-name "~/.emacs.d/bookmarks"))
(add-to-list 'recentf-exclude
(expand-file-name "~/Documents/drive/org/elfeed/*")))
#+END_SRC
** =tex=
As previously described, “the big boy”. I know little about most of these settings, but I think theyre the default ones.
#+BEGIN_SRC emacs-lisp
(use-package tex
;; the big boy
:ensure auctex
:mode ("\\.tex\\'" . latex-mode)
:init
(add-hook 'LaTeX-mode-hook 'turn-on-auto-fill)
(add-hook 'TeX-after-compilation-finished-functions
#'TeX-revert-document-buffer)
:config
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)
(setq-default TeX-engine 'xetex)
(setq-default TeX-PDF-mode t)
(setq TeX-view-program-selection '((output-pdf "PDF Tools"))
TeX-source-correlate-start-server t))
#+END_SRC
** =typo=
Automatically use smart quotes in text modes. (This was set up with =org-mode-hook=, but surely should be =text-mode-hook=? Will revert if necessary.)
#+BEGIN_SRC emacs-lisp
(use-package typo
;; smart quotes
:custom
(typo-global-mode 1)
:init
(add-hook 'text-mode-hook 'typo-mode))
#+END_SRC
** =yasnippet=
Per-mode text expansion.
#+BEGIN_SRC emacs-lisp
(use-package yasnippet
:config
(setq yas-snippet-dirs '("~/.emacs.d/snippets")))
(yas-global-mode 1)
#+END_SRC
* Aesthetics
** Packages
*** =all-the-icons=
Shows nice icons in the modeline and in =neotree=. Fonts need to be installed manually on Windows, possibly because of permissions issues or because of where the Emacs binary lives or maybe both those things.
#+BEGIN_SRC emacs-lisp
(use-package all-the-icons
:config
(unless (iswin)
(when (not (member "all-the-icons" (font-family-list)))
(all-the-icons-install-fonts t))))
#+END_SRC
*** =emojify=
Support for various types of emoge.
#+BEGIN_SRC emacs-lisp
(use-package emojify
:init
(add-hook 'after-init-hook #'global-emojify-mode))
#+END_SRC
*** =hl-line=
Highlights current line.
#+BEGIN_SRC emacs-lisp
(use-package hl-line
:config
(global-hl-line-mode 1))
#+END_SRC
*** =tao-theme=
Nice monochrome-ish light theme, reminiscent of [[https://edwardtufte.github.io/tufte-css/][Tufte CSS]].
#+BEGIN_SRC emacs-lisp
(use-package tao-theme)
(load-theme 'tao-yang t)
(set-cursor-color "#61805c")
(set-face-attribute 'region nil :background "#fcf6a7")
(set-face-background 'hl-line "#ddffd6")
#+END_SRC
** Fonts
Use Noto fonts to match my system fonts on Linux. This has to be done differently on Windows for some reason.
#+BEGIN_SRC emacs-lisp
(if (iswin)
(custom-set-faces
'(default ((t (:family "Noto Mono" :foundry "outline" :slant normal :weight normal :height 98 :width normal))))
'(italic ((t (:slant italic))))
'(variable-pitch ((t (:family "Noto Sans" :height 90))))
'(fixed-pitch ((t (:family "Noto Mono" :height 90))))))
(unless (iswin)
(custom-set-faces
'(italic ((t (:slant italic))))
'(variable-pitch ((t (:family "Noto Sans" :height 90))))
'(fixed-pitch ((t (:family "Noto Mono" :height 90))))))
#+END_SRC
Use the =mixed-pitch= package to determine the font intelligently in modes that contain both text and prog elements.
#+BEGIN_SRC emacs-lisp
(use-package mixed-pitch
:hook
(LaTeX-mode . mixed-pitch-mode)
(org-mode . mixed-pitch-mode)
(markdown-mode . mixed-pitch-mode))
#+END_SRC
* Startup
Firstly, tell Emacs where to look for custom functions.
#+BEGIN_SRC emacs-lisp
(defun load-directory (dir)
(let ((load-it (lambda (f)
(load-file (concat (file-name-as-directory dir) f)))))
(mapc load-it (directory-files dir nil "\\.el$"))))
(load-directory "~/.emacs.d/custom/")
#+END_SRC
Set the =*scratch*= buffer to org-mode.
#+BEGIN_SRC emacs-lisp
(setq initial-major-mode 'org-mode)
#+END_SRC
Tell me what version of Emacs Im using.
#+BEGIN_SRC emacs-lisp
(setq initial-scratch-message
(concat "# emacs " (number-to-string emacs-major-version) " on " (symbol-name system-type) "\n\n"))
#+END_SRC
Finally, because org gets very confused by all these settings, give it a friendly reload.
#+BEGIN_SRC emacs-lisp
(org-reload)
#+END_SRC
Loading…
Cancel
Save