From 5d6100dd0e9e12bccc319ab1971aa300b4af2d58 Mon Sep 17 00:00:00 2001 From: luxick Date: Tue, 12 Nov 2019 14:11:39 +0100 Subject: [PATCH] Variable pitch mode for org files. --- setup-emacs.org | 476 +++++++++++++++++++++++++----------------------- 1 file changed, 250 insertions(+), 226 deletions(-) diff --git a/setup-emacs.org b/setup-emacs.org index 9bdb3c3..2c7875a 100644 --- a/setup-emacs.org +++ b/setup-emacs.org @@ -1,35 +1,35 @@ #+TITLE: Emacs Configuration This is my configuration for the emacs editor. * Set up UI - Remove all those UI elements. They do not look good and waste space. - #+BEGIN_SRC emacs-lisp +Remove all those UI elements. They do not look good and waste space. +#+BEGIN_SRC emacs-lisp (tool-bar-mode -1) (menu-bar-mode -1) (scroll-bar-mode -1) (tooltip-mode -1) (fringe-mode -1) - #+END_SRC +#+END_SRC * Set up package repositories ** Require package support - State that we will need package support and define a macro for adding package repos to the archives - #+BEGIN_SRC emacs-lisp +State that we will need package support and define a macro for adding package repos to the archives +#+BEGIN_SRC emacs-lisp (require 'package) (defmacro append-to-list (target suffix) "Append SUFFIX to TARGET in place." `(setq ,target (append ,target ,suffix))) - #+END_SRC +#+END_SRC ** Add package repos - #+BEGIN_SRC emacs-lisp +#+BEGIN_SRC emacs-lisp (append-to-list package-archives '(("melpa" . "http://melpa.org/packages/") ("melpa-stable" . "http://stable.melpa.org/packages/") ("org-elpa" . "https://orgmode.org/elpa/"))) - #+END_SRC +#+END_SRC ** Ensure ~use-package~ command is present - #+BEGIN_SRC emacs-lisp +#+BEGIN_SRC emacs-lisp (package-initialize) (unless (package-installed-p 'use-package) @@ -43,42 +43,42 @@ This is my configuration for the emacs editor. use-package-verbose t) (use-package gnu-elpa-keyring-update) - #+END_SRC +#+END_SRC * Set Backup Location - Emacs, by default clutters the file system with backup files. - We do not want them to be right next to the actual file, so we tell emacs to use dedicated directory to store them. - While we are at it, we also set rule for how many version emacs should keep as backups. - #+BEGIN_SRC emacs-lisp +Emacs, by default clutters the file system with backup files. +We do not want them to be right next to the actual file, so we tell emacs to use dedicated directory to store them. +While we are at it, we also set rule for how many version emacs should keep as backups. +#+BEGIN_SRC emacs-lisp (setq backup-directory-alist `(("." . "~/.emacs-backup"))) (setq backup-by-copying t) (setq delete-old-versions t kept-new-versions 6 kept-old-versions 2 version-control t) - #+END_SRC +#+END_SRC * Define useful functions ** Edit the config file - A simple funtion to open this file for quick editing. - #+BEGIN_SRC emacs-lisp +A simple funtion to open this file for quick editing. +#+BEGIN_SRC emacs-lisp (defun edit-config () (interactive) (find-file "~/.emacs.d/setup-emacs.org")) - #+END_SRC +#+END_SRC ** Reformat a whole buffer - Reindet the whole buffer with ~F12~ - #+BEGIN_SRC emacs-lisp +Reindet the whole buffer with ~F12~ +#+BEGIN_SRC emacs-lisp (defun indent-buffer () (interactive) (save-excursion (indent-region (point-min) (point-max) nil))) (global-set-key [f12] 'indent-buffer) - #+END_SRC +#+END_SRC ** Split windows and immediately switch to it - #+BEGIN_SRC emacs-lisp +#+BEGIN_SRC emacs-lisp (defun split-right-and-enter () "Split the window to the right and enter it." (interactive) @@ -90,19 +90,19 @@ This is my configuration for the emacs editor. (interactive) (split-window-below) (other-window 1)) - #+END_SRC +#+END_SRC ** Quick buffer switching - #+BEGIN_SRC emacs-lisp +#+BEGIN_SRC emacs-lisp (defun switch-to-previous-buffer () "Switch to previously open buffer. Repeated invocations toggle between the two most recently open buffers." (interactive) (switch-to-buffer (other-buffer (current-buffer) 1))) - #+END_SRC +#+END_SRC * Theming ** Main Theme - #+BEGIN_SRC emacs-lisp +#+BEGIN_SRC emacs-lisp (use-package doom-themes) ;; Global settings (defaults) @@ -118,35 +118,56 @@ This is my configuration for the emacs editor. ;; Corrects (and improves) org-mode's native fontification. (doom-themes-org-config) - #+END_SRC +#+END_SRC ** Modeline - #+BEGIN_SRC emacs-lisp +#+BEGIN_SRC emacs-lisp (use-package doom-modeline :ensure t :hook (after-init . doom-modeline-mode)) - #+END_SRC +#+END_SRC *** Minions Menu - Add a menu to the modeline to access all minor modes. - #+BEGIN_SRC emacs-lisp +Add a menu to the modeline to access all minor modes. +#+BEGIN_SRC emacs-lisp (use-package minions :config (minions-mode 1)) - #+END_SRC +#+END_SRC ** Font - #+BEGIN_SRC emacs-lisp - (set-face-attribute 'default nil - :family "Hack" - :height 110 - :weight 'normal - :width 'normal) - #+END_SRC +Set up the fonts that should be used by emacs. +#+BEGIN_SRC emacs-lisp + (set-face-attribute 'default nil + :family "Hack" + :height 110 + :weight 'normal + :width 'normal) + (custom-theme-set-faces + 'user + '(variable-pitch ((t (:family "Source Sans Pro" :height 1.1 :weight light)))) + '(fixed-pitch ((t ( :family "Hack" :slant normal :weight normal :height 1.0 :width normal))))) +#+END_SRC + +This sets different fonts for special blocks in org-mode. So that when ~variable-pitch~ mode is active code block are not broken. +#+BEGIN_SRC emacs-lisp + (custom-theme-set-faces + 'user + '(org-block ((t (:inherit fixed-pitch)))) + '(org-document-info-keyword ((t (:inherit (shadow fixed-pitch))))) + '(org-link ((t (:foreground "royal blue" :underline t)))) + '(org-meta-line ((t (:inherit (font-lock-comment-face fixed-pitch))))) + '(org-property-value ((t (:inherit fixed-pitch))) t) + '(org-special-keyword ((t (:inherit (font-lock-comment-face fixed-pitch))))) + '(org-tag ((t (:inherit (shadow fixed-pitch) :weight bold :height 0.8)))) + '(org-verbatim ((t (:inherit (shadow fixed-pitch))))) + '(org-table ((t (:inherit (shadow fixed-pitch))))) + '(org-indent ((t (:inherit (org-hide fixed-pitch)))))) +#+END_SRC * Ivy - Use Ivy to make minibuf promts better. Adds the ability to sort and filter. +Use Ivy to make minibuf promts better. Adds the ability to sort and filter. ** Use Ivy - #+BEGIN_SRC emacs-lisp +#+BEGIN_SRC emacs-lisp (use-package ivy :init (ivy-mode 1) @@ -174,16 +195,16 @@ This is my configuration for the emacs editor. (ivy-rich-mode)) (use-package ivy-hydra) - #+END_SRC +#+END_SRC ** Smex - Sort commands by recency in ivy windows - #+BEGIN_SRC emacs-lisp +Sort commands by recency in ivy windows +#+BEGIN_SRC emacs-lisp (use-package smex) - #+END_SRC +#+END_SRC * Counsel - #+BEGIN_SRC emacs-lisp +#+BEGIN_SRC emacs-lisp (use-package counsel :ensure t :after ivy @@ -199,12 +220,12 @@ This is my configuration for the emacs editor. :map ivy-minibuffer-map ("C-r" . counsel-minibuffer-history)) :diminish) - #+END_SRC +#+END_SRC * Undo Tree - Using the beauty that is undo-tree, we can easily navigate through history of a buffer. - This includes obviously going back in edit history, but also branching of end returning to previous states. - #+BEGIN_SRC emacs-lisp +Using the beauty that is undo-tree, we can easily navigate through history of a buffer. +This includes obviously going back in edit history, but also branching of end returning to previous states. +#+BEGIN_SRC emacs-lisp (use-package undo-tree :bind (("C-x u" . undo-tree-visualize) ("C-z" . undo-tree-undo) @@ -221,13 +242,13 @@ This is my configuration for the emacs editor. :bind (("C-c _" . undo-propose) :map undo-propose-mode-map ("" . undo-only))) - #+END_SRC - With this we can use ~C-x u~ in any buffer to bring up the tree and navigate it using the arrow key. - Once in a state we agree with, just press ~q~ and we are done. +#+END_SRC +With this we can use ~C-x u~ in any buffer to bring up the tree and navigate it using the arrow key. +Once in a state we agree with, just press ~q~ and we are done. * Magit - Magit is THE go to package for using git in emacs. - #+BEGIN_SRC emacs-lisp +Magit is THE go to package for using git in emacs. +#+BEGIN_SRC emacs-lisp (use-package magit :bind (("C-c g" . magit-status)) :diminish magit-auto-revert-mode @@ -245,11 +266,11 @@ This is my configuration for the emacs editor. (use-package libgit :disabled :after magit) - #+END_SRC - The ~advice-add~ entries are thereto stop magit from bugging us to save buffers when commiting and refreshing. +#+END_SRC +The ~advice-add~ entries are thereto stop magit from bugging us to save buffers when commiting and refreshing. ** Helper Functions - #+BEGIN_SRC emacs-lisp +#+BEGIN_SRC emacs-lisp (autoload 'diff-no-select "diff") (defun current-buffer-matches-file-p () "Return t if the current buffer is identical to its associated file." @@ -257,10 +278,10 @@ This is my configuration for the emacs editor. (diff-no-select buffer-file-name (current-buffer) nil 'noasync) (with-current-buffer "*Diff*" (and (search-forward-regexp "^Diff finished \(no differences\)\." (point-max) 'noerror) t)))) - #+END_SRC +#+END_SRC - Clear modified bit on all unmodified buffers - #+BEGIN_SRC emacs-lisp +Clear modified bit on all unmodified buffers +#+BEGIN_SRC emacs-lisp (defun maybe-unset-buffer-modified (&optional _) (interactive) (dolist (buf (buffer-list)) @@ -268,115 +289,118 @@ This is my configuration for the emacs editor. (when (and buffer-file-name (buffer-modified-p) (current-buffer-matches-file-p)) (set-buffer-modified-p nil))))) - #+END_SRC +#+END_SRC - Don't prompt to save unmodified buffers on exit. - #+BEGIN_SRC emacs-lisp +Don't prompt to save unmodified buffers on exit. +#+BEGIN_SRC emacs-lisp (advice-add 'save-buffers-kill-emacs :before #'maybe-unset-buffer-modified) - #+END_SRC +#+END_SRC - #+BEGIN_SRC emacs-lisp +#+BEGIN_SRC emacs-lisp (defun kill-buffer-with-prejudice (&optional _) "Kill a buffer, eliding the save dialogue if there are no diffs." (interactive) (when (current-buffer-matches-file-p) (set-buffer-modified-p nil)) (kill-buffer)) - #+END_SRC +#+END_SRC * Org Mode ** Define important files *** The Link Dump - I use a single file to dump all links I plan on viewing later. - #+BEGIN_SRC emacs-lisp +I use a single file to dump all links I plan on viewing later. +#+BEGIN_SRC emacs-lisp (defun open-link-list () (interactive) (find-file "~/Notes/links.org")) - #+END_SRC +#+END_SRC *** The Quick Note File - This file serves as a notepad for wirting down all sorts of things that have not yet been refiled. - #+BEGIN_SRC emacs-lisp +This file serves as a notepad for wirting down all sorts of things that have not yet been refiled. +#+BEGIN_SRC emacs-lisp (defun open-semantic-notes () (interactive) (find-file "~/Notes/semantic.org")) - #+END_SRC +#+END_SRC *** The TODO File - This file will track the bulk of all todo items we will enter. - #+BEGIN_SRC emacs-lisp +This file will track the bulk of all todo items we will enter. +#+BEGIN_SRC emacs-lisp (defun open-main-todo-file () (interactive) (find-file "~/Notes/todo.org")) - #+END_SRC +#+END_SRC *** The Tracking file - I use this file to capture dates, at wich I do certain tasks. - Used mostly for keeping track of habits. - #+BEGIN_SRC emacs-lisp +I use this file to capture dates, at wich I do certain tasks. +Used mostly for keeping track of habits. +#+BEGIN_SRC emacs-lisp (defun open-main-todo-file () (interactive) (find-file "~/Notes/tracking.org")) - #+END_SRC +#+END_SRC ** Configure org-mode - This is the main configuration for the infamous org-mode. - The most important parts are configuring key bindings to quickly access the files we have defined above. - #+BEGIN_SRC emacs-lisp - (use-package org - ;; Always get this from the GNU archive. - :pin gnu - :bind (("C-c o c" . org-capture) - ("C-c o n" . open-semantic-notes) - ("C-c o t" . open-main-todo-file) - ("C-c o l" . open-link-list) - ("C-c o s" . org-store-link) - ("C-c o a" . org-agenda) - :map org-mode-map - ("M-s-" . org-insert-todo-heading) - ("C-c c" . org-mode-insert-code) - ("C-c a s" . org-emphasize) - ("C-c a r" . org-ref) - ("C-c a e" . outline-show-all) - ("C-c a t" . unindent-by-four)) - :hook (org-mode . visual-line-mode) - :config - (let ((todo-path (expand-file-name "~/Notes/todo.org"))) - (when (file-exists-p todo-path) - (setq org-agenda-files (list todo-path) - org-default-notes-file todo-path))) +This is the main configuration for the infamous org-mode. +The most important parts are configuring key bindings to quickly access the files we have defined above. +#+BEGIN_SRC emacs-lisp + (use-package org + ;; Always get this from the GNU archive. + :pin gnu + :bind (("C-c o c" . org-capture) + ("C-c o n" . open-semantic-notes) + ("C-c o t" . open-main-todo-file) + ("C-c o l" . open-link-list) + ("C-c o s" . org-store-link) + ("C-c o a" . org-agenda) + :map org-mode-map + ("M-s-" . org-insert-todo-heading) + ("M-" . org-insert-heading-respect-content) + ("C-c c" . org-mode-insert-code) + ("C-c a s" . org-emphasize) + ("C-c a r" . org-ref) + ("C-c a e" . outline-show-all) + ("C-c a t" . unindent-by-four)) + :hook ((org-mode . visual-line-mode) + (org-mode . variable-pitch-mode) + (org-mode . org-indent-mode)) + :config + (let ((todo-path (expand-file-name "~/Notes/todo.org"))) + (when (file-exists-p todo-path) + (setq org-agenda-files (list todo-path) + org-default-notes-file todo-path))) - (setq org-footnote-section "" - org-startup-with-inline-images t - org-pretty-entities t - org-indent-mode t - org-ellipsis "…" - org-footnote-section nil - org-hide-leading-stars nil - ) - (setcar (nthcdr 4 org-emphasis-regexp-components) 4) + (setq org-footnote-section "" + org-startup-with-inline-images t + org-pretty-entities t + org-indent-mode t + org-ellipsis "⤵" + org-footnote-section nil + org-hide-leading-stars nil + ) + (setcar (nthcdr 4 org-emphasis-regexp-components) 4) - (defun org-mode-insert-code () - (interactive) - (org-emphasize ?~))) - #+END_SRC + (defun org-mode-insert-code () + (interactive) + (org-emphasize ?~))) +#+END_SRC ** Set default archive location - When archiving items in org files, the default ist to crate a separate file named ~.org_archive~. - This clutters up my notes folder quite a bit, as I use a lot of separate files with thier respective archives. - All archives should be stored in a single ~.archive~ file per directory. - #+BEGIN_SRC emacs-lisp +When archiving items in org files, the default ist to crate a separate file named ~.org_archive~. +This clutters up my notes folder quite a bit, as I use a lot of separate files with thier respective archives. +All archives should be stored in a single ~.archive~ file per directory. +#+BEGIN_SRC emacs-lisp (setq org-archive-location "./.archive::* From %s") - #+END_SRC +#+END_SRC ** Beautify org-mode *** Icons for headline indentation - #+BEGIN_SRC emacs-lisp +#+BEGIN_SRC emacs-lisp (use-package org-bullets :init (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))) - #+END_SRC +#+END_SRC *** Replace checkmark with unicode icons - #+BEGIN_SRC emacs-lisp +#+BEGIN_SRC emacs-lisp (use-package pretty-mode :init (global-pretty-mode t)) @@ -386,10 +410,10 @@ This is my configuration for the emacs editor. (push '("[X]" . "☑" ) prettify-symbols-alist) (push '("[-]" . "❍" ) prettify-symbols-alist) (prettify-symbols-mode))) - #+END_SRC +#+END_SRC *** Strike out done ckeckbox items - #+BEGIN_SRC emacs-lisp +#+BEGIN_SRC emacs-lisp (defface org-checkbox-done-text '((t (:foreground "#71696A" :strike-through t))) "Face for the text part of a checked org-mode checkbox.") @@ -399,21 +423,21 @@ This is my configuration for the emacs editor. `(("^[ \t]*\\(?:[-+*]\\|[0-9]+[).]\\)[ \t]+\\(\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\[\\(?:X\\|\\([0-9]+\\)/\\2\\)\\][^\n]*\n\\)" 1 'org-checkbox-done-text prepend)) 'append) - #+END_SRC +#+END_SRC ** CSS Themes for Exports - When exporting from org-mode (usually to HTML) we want to specify additional styles. - #+BEGIN_SRC emacs-lisp +When exporting from org-mode (usually to HTML) we want to specify additional styles. +#+BEGIN_SRC emacs-lisp (defvar org-theme-css-dir "~/.emacs.d/org-css/") - #+END_SRC +#+END_SRC - Pack some ~.css~ files into this directory. They will be available for choosing when exporting. - The folowing code will define a function to inline css into a self-contained html file. +Pack some ~.css~ files into this directory. They will be available for choosing when exporting. +The folowing code will define a function to inline css into a self-contained html file. - To use it type ~M-x toggle-org-custom-inline-style~ into an org-mode buffer. - When exporting to HTML emacs will ask which css theme to use. +To use it type ~M-x toggle-org-custom-inline-style~ into an org-mode buffer. +When exporting to HTML emacs will ask which css theme to use. - #+BEGIN_SRC emacs-lisp +#+BEGIN_SRC emacs-lisp (defun toggle-org-custom-inline-style () (interactive) (let ((hook 'org-export-before-parsing-hook) @@ -450,11 +474,11 @@ This is my configuration for the emacs editor. nil) (message "Set custom style from %s" f)) (message "Custom header file %s doesnt exist"))))) - #+END_SRC +#+END_SRC ** Prettier Timestamps in Exports - The default timestamps look pretty unintuitive, with all the angle brackets and all. Let's make them look better. - #+BEGIN_SRC emacs-lisp +The default timestamps look pretty unintuitive, with all the angle brackets and all. Let's make them look better. +#+BEGIN_SRC emacs-lisp ;;(add-to-list 'org-export-filter-timestamp-functions ;; #'endless/filter-timestamp) ;;(defun endless/filter-timestamp (trans back _comm) @@ -463,32 +487,32 @@ This is my configuration for the emacs editor. ;; (replace-regexp-in-string "&[lg]t;" "" trans)) ;; (`latex ;; (replace-regexp-in-string "[<>]" "" trans)))) - #+END_SRC - Removed for now, this somehow breaks emacs +#+END_SRC +Removed for now, this somehow breaks emacs - OK, no more brackets. Now for a better formatted display. +OK, no more brackets. Now for a better formatted display. - #+BEGIN_SRC emacs-lisp +#+BEGIN_SRC emacs-lisp (setq-default org-display-custom-times t) (setq org-time-stamp-custom-formats '("<%a %d.%m.%Y>" . "<%d.%m.%y %H:%M>")) - #+END_SRC +#+END_SRC ** Templates *** Babel - Here we set custom templates to be used for structure expansion. - These are used when we type "<" folowed by the shortcut for a template and hit "TAB". - e.g. "" 'end-of-buffer) (bind-key "C-x C-b" 'ibuffer) ;; buffer-list is not a good default - #+END_SRC +#+END_SRC ** Unbind some default key bindings - #+BEGIN_SRC emacs-lisp +#+BEGIN_SRC emacs-lisp (unbind-key "C-") ;; prevent switching to tab mode randomly (unbind-key "C-h n") ;; I have never wanted to see emacs news ever (unbind-key "C-h C-n") ;; why on earth is it bound to two keybindings?? (unbind-key "C-x C-d") ;; list-directory is utterly useless given the existence of dired (unbind-key "C-x C-r") ;; as is find-file-read-only - #+END_SRC +#+END_SRC * Load ~custom.el~ - Load a custom file from the emacs home dir. - This file is specific to the maschine emacs runs on. - It conatins customizations and file locations that are maschine dependend. - #+BEGIN_SRC emacs-lisp +Load a custom file from the emacs home dir. +This file is specific to the maschine emacs runs on. +It conatins customizations and file locations that are maschine dependend. +#+BEGIN_SRC emacs-lisp (setq custom-file "~/.emacs.d/custom.el") (load custom-file 'noerror) - #+END_SRC +#+END_SRC