Variable pitch mode for org files.

This commit is contained in:
2019-11-12 14:11:39 +01:00
parent 638544f974
commit 5d6100dd0e

View File

@@ -1,35 +1,35 @@
#+TITLE: Emacs Configuration #+TITLE: Emacs Configuration
This is my configuration for the emacs editor. This is my configuration for the emacs editor.
* Set up UI * Set up UI
Remove all those UI elements. They do not look good and waste space. Remove all those UI elements. They do not look good and waste space.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(tool-bar-mode -1) (tool-bar-mode -1)
(menu-bar-mode -1) (menu-bar-mode -1)
(scroll-bar-mode -1) (scroll-bar-mode -1)
(tooltip-mode -1) (tooltip-mode -1)
(fringe-mode -1) (fringe-mode -1)
#+END_SRC #+END_SRC
* Set up package repositories * Set up package repositories
** Require package support ** Require package support
State that we will need package support and define a macro for adding package repos to the archives State that we will need package support and define a macro for adding package repos to the archives
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(require 'package) (require 'package)
(defmacro append-to-list (target suffix) (defmacro append-to-list (target suffix)
"Append SUFFIX to TARGET in place." "Append SUFFIX to TARGET in place."
`(setq ,target (append ,target ,suffix))) `(setq ,target (append ,target ,suffix)))
#+END_SRC #+END_SRC
** Add package repos ** Add package repos
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(append-to-list package-archives (append-to-list package-archives
'(("melpa" . "http://melpa.org/packages/") '(("melpa" . "http://melpa.org/packages/")
("melpa-stable" . "http://stable.melpa.org/packages/") ("melpa-stable" . "http://stable.melpa.org/packages/")
("org-elpa" . "https://orgmode.org/elpa/"))) ("org-elpa" . "https://orgmode.org/elpa/")))
#+END_SRC #+END_SRC
** Ensure ~use-package~ command is present ** Ensure ~use-package~ command is present
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(package-initialize) (package-initialize)
(unless (package-installed-p 'use-package) (unless (package-installed-p 'use-package)
@@ -43,42 +43,42 @@ This is my configuration for the emacs editor.
use-package-verbose t) use-package-verbose t)
(use-package gnu-elpa-keyring-update) (use-package gnu-elpa-keyring-update)
#+END_SRC #+END_SRC
* Set Backup Location * Set Backup Location
Emacs, by default clutters the file system with backup files. 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. 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. While we are at it, we also set rule for how many version emacs should keep as backups.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(setq backup-directory-alist `(("." . "~/.emacs-backup"))) (setq backup-directory-alist `(("." . "~/.emacs-backup")))
(setq backup-by-copying t) (setq backup-by-copying t)
(setq delete-old-versions t (setq delete-old-versions t
kept-new-versions 6 kept-new-versions 6
kept-old-versions 2 kept-old-versions 2
version-control t) version-control t)
#+END_SRC #+END_SRC
* Define useful functions * Define useful functions
** Edit the config file ** Edit the config file
A simple funtion to open this file for quick editing. A simple funtion to open this file for quick editing.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun edit-config () (defun edit-config ()
(interactive) (interactive)
(find-file "~/.emacs.d/setup-emacs.org")) (find-file "~/.emacs.d/setup-emacs.org"))
#+END_SRC #+END_SRC
** Reformat a whole buffer ** Reformat a whole buffer
Reindet the whole buffer with ~F12~ Reindet the whole buffer with ~F12~
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun indent-buffer () (defun indent-buffer ()
(interactive) (interactive)
(save-excursion (save-excursion
(indent-region (point-min) (point-max) nil))) (indent-region (point-min) (point-max) nil)))
(global-set-key [f12] 'indent-buffer) (global-set-key [f12] 'indent-buffer)
#+END_SRC #+END_SRC
** Split windows and immediately switch to it ** Split windows and immediately switch to it
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun split-right-and-enter () (defun split-right-and-enter ()
"Split the window to the right and enter it." "Split the window to the right and enter it."
(interactive) (interactive)
@@ -90,19 +90,19 @@ This is my configuration for the emacs editor.
(interactive) (interactive)
(split-window-below) (split-window-below)
(other-window 1)) (other-window 1))
#+END_SRC #+END_SRC
** Quick buffer switching ** Quick buffer switching
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun switch-to-previous-buffer () (defun switch-to-previous-buffer ()
"Switch to previously open buffer. Repeated invocations toggle between the two most recently open buffers." "Switch to previously open buffer. Repeated invocations toggle between the two most recently open buffers."
(interactive) (interactive)
(switch-to-buffer (other-buffer (current-buffer) 1))) (switch-to-buffer (other-buffer (current-buffer) 1)))
#+END_SRC #+END_SRC
* Theming * Theming
** Main Theme ** Main Theme
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package doom-themes) (use-package doom-themes)
;; Global settings (defaults) ;; Global settings (defaults)
@@ -118,35 +118,56 @@ This is my configuration for the emacs editor.
;; Corrects (and improves) org-mode's native fontification. ;; Corrects (and improves) org-mode's native fontification.
(doom-themes-org-config) (doom-themes-org-config)
#+END_SRC #+END_SRC
** Modeline ** Modeline
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package doom-modeline (use-package doom-modeline
:ensure t :ensure t
:hook (after-init . doom-modeline-mode)) :hook (after-init . doom-modeline-mode))
#+END_SRC #+END_SRC
*** Minions Menu *** Minions Menu
Add a menu to the modeline to access all minor modes. Add a menu to the modeline to access all minor modes.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package minions (use-package minions
:config (minions-mode 1)) :config (minions-mode 1))
#+END_SRC #+END_SRC
** Font ** Font
#+BEGIN_SRC emacs-lisp Set up the fonts that should be used by emacs.
(set-face-attribute 'default nil #+BEGIN_SRC emacs-lisp
:family "Hack" (set-face-attribute 'default nil
:height 110 :family "Hack"
:weight 'normal :height 110
:width 'normal) :weight 'normal
#+END_SRC :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 * 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 ** Use Ivy
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package ivy (use-package ivy
:init :init
(ivy-mode 1) (ivy-mode 1)
@@ -174,16 +195,16 @@ This is my configuration for the emacs editor.
(ivy-rich-mode)) (ivy-rich-mode))
(use-package ivy-hydra) (use-package ivy-hydra)
#+END_SRC #+END_SRC
** Smex ** Smex
Sort commands by recency in ivy windows Sort commands by recency in ivy windows
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package smex) (use-package smex)
#+END_SRC #+END_SRC
* Counsel * Counsel
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package counsel (use-package counsel
:ensure t :ensure t
:after ivy :after ivy
@@ -199,12 +220,12 @@ This is my configuration for the emacs editor.
:map ivy-minibuffer-map :map ivy-minibuffer-map
("C-r" . counsel-minibuffer-history)) ("C-r" . counsel-minibuffer-history))
:diminish) :diminish)
#+END_SRC #+END_SRC
* Undo Tree * Undo Tree
Using the beauty that is undo-tree, we can easily navigate through history of a buffer. 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. This includes obviously going back in edit history, but also branching of end returning to previous states.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package undo-tree (use-package undo-tree
:bind (("C-x u" . undo-tree-visualize) :bind (("C-x u" . undo-tree-visualize)
("C-z" . undo-tree-undo) ("C-z" . undo-tree-undo)
@@ -221,13 +242,13 @@ This is my configuration for the emacs editor.
:bind (("C-c _" . undo-propose) :bind (("C-c _" . undo-propose)
:map undo-propose-mode-map :map undo-propose-mode-map
("<up>" . undo-only))) ("<up>" . undo-only)))
#+END_SRC #+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. 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. Once in a state we agree with, just press ~q~ and we are done.
* Magit * Magit
Magit is THE go to package for using git in emacs. Magit is THE go to package for using git in emacs.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package magit (use-package magit
:bind (("C-c g" . magit-status)) :bind (("C-c g" . magit-status))
:diminish magit-auto-revert-mode :diminish magit-auto-revert-mode
@@ -245,11 +266,11 @@ This is my configuration for the emacs editor.
(use-package libgit (use-package libgit
:disabled :disabled
:after magit) :after magit)
#+END_SRC #+END_SRC
The ~advice-add~ entries are thereto stop magit from bugging us to save buffers when commiting and refreshing. The ~advice-add~ entries are thereto stop magit from bugging us to save buffers when commiting and refreshing.
** Helper Functions ** Helper Functions
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(autoload 'diff-no-select "diff") (autoload 'diff-no-select "diff")
(defun current-buffer-matches-file-p () (defun current-buffer-matches-file-p ()
"Return t if the current buffer is identical to its associated file." "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) (diff-no-select buffer-file-name (current-buffer) nil 'noasync)
(with-current-buffer "*Diff*" (with-current-buffer "*Diff*"
(and (search-forward-regexp "^Diff finished \(no differences\)\." (point-max) 'noerror) t)))) (and (search-forward-regexp "^Diff finished \(no differences\)\." (point-max) 'noerror) t))))
#+END_SRC #+END_SRC
Clear modified bit on all unmodified buffers Clear modified bit on all unmodified buffers
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun maybe-unset-buffer-modified (&optional _) (defun maybe-unset-buffer-modified (&optional _)
(interactive) (interactive)
(dolist (buf (buffer-list)) (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)) (when (and buffer-file-name (buffer-modified-p) (current-buffer-matches-file-p))
(set-buffer-modified-p nil))))) (set-buffer-modified-p nil)))))
#+END_SRC #+END_SRC
Don't prompt to save unmodified buffers on exit. Don't prompt to save unmodified buffers on exit.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(advice-add 'save-buffers-kill-emacs :before #'maybe-unset-buffer-modified) (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 _) (defun kill-buffer-with-prejudice (&optional _)
"Kill a buffer, eliding the save dialogue if there are no diffs." "Kill a buffer, eliding the save dialogue if there are no diffs."
(interactive) (interactive)
(when (current-buffer-matches-file-p) (set-buffer-modified-p nil)) (when (current-buffer-matches-file-p) (set-buffer-modified-p nil))
(kill-buffer)) (kill-buffer))
#+END_SRC #+END_SRC
* Org Mode * Org Mode
** Define important files ** Define important files
*** The Link Dump *** The Link Dump
I use a single file to dump all links I plan on viewing later. I use a single file to dump all links I plan on viewing later.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun open-link-list () (defun open-link-list ()
(interactive) (interactive)
(find-file "~/Notes/links.org")) (find-file "~/Notes/links.org"))
#+END_SRC #+END_SRC
*** The Quick Note File *** The Quick Note File
This file serves as a notepad for wirting down all sorts of things that have not yet been refiled. This file serves as a notepad for wirting down all sorts of things that have not yet been refiled.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun open-semantic-notes () (defun open-semantic-notes ()
(interactive) (interactive)
(find-file "~/Notes/semantic.org")) (find-file "~/Notes/semantic.org"))
#+END_SRC #+END_SRC
*** The TODO File *** The TODO File
This file will track the bulk of all todo items we will enter. This file will track the bulk of all todo items we will enter.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun open-main-todo-file () (defun open-main-todo-file ()
(interactive) (interactive)
(find-file "~/Notes/todo.org")) (find-file "~/Notes/todo.org"))
#+END_SRC #+END_SRC
*** The Tracking file *** The Tracking file
I use this file to capture dates, at wich I do certain tasks. I use this file to capture dates, at wich I do certain tasks.
Used mostly for keeping track of habits. Used mostly for keeping track of habits.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun open-main-todo-file () (defun open-main-todo-file ()
(interactive) (interactive)
(find-file "~/Notes/tracking.org")) (find-file "~/Notes/tracking.org"))
#+END_SRC #+END_SRC
** Configure org-mode ** Configure org-mode
This is the main configuration for the infamous 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. The most important parts are configuring key bindings to quickly access the files we have defined above.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package org (use-package org
;; Always get this from the GNU archive. ;; Always get this from the GNU archive.
:pin gnu :pin gnu
:bind (("C-c o c" . org-capture) :bind (("C-c o c" . org-capture)
("C-c o n" . open-semantic-notes) ("C-c o n" . open-semantic-notes)
("C-c o t" . open-main-todo-file) ("C-c o t" . open-main-todo-file)
("C-c o l" . open-link-list) ("C-c o l" . open-link-list)
("C-c o s" . org-store-link) ("C-c o s" . org-store-link)
("C-c o a" . org-agenda) ("C-c o a" . org-agenda)
:map org-mode-map :map org-mode-map
("M-s-<return>" . org-insert-todo-heading) ("M-s-<return>" . org-insert-todo-heading)
("C-c c" . org-mode-insert-code) ("M-<return>" . org-insert-heading-respect-content)
("C-c a s" . org-emphasize) ("C-c c" . org-mode-insert-code)
("C-c a r" . org-ref) ("C-c a s" . org-emphasize)
("C-c a e" . outline-show-all) ("C-c a r" . org-ref)
("C-c a t" . unindent-by-four)) ("C-c a e" . outline-show-all)
:hook (org-mode . visual-line-mode) ("C-c a t" . unindent-by-four))
:config :hook ((org-mode . visual-line-mode)
(let ((todo-path (expand-file-name "~/Notes/todo.org"))) (org-mode . variable-pitch-mode)
(when (file-exists-p todo-path) (org-mode . org-indent-mode))
(setq org-agenda-files (list todo-path) :config
org-default-notes-file todo-path))) (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 "" (setq org-footnote-section ""
org-startup-with-inline-images t org-startup-with-inline-images t
org-pretty-entities t org-pretty-entities t
org-indent-mode t org-indent-mode t
org-ellipsis "" org-ellipsis ""
org-footnote-section nil org-footnote-section nil
org-hide-leading-stars nil org-hide-leading-stars nil
) )
(setcar (nthcdr 4 org-emphasis-regexp-components) 4) (setcar (nthcdr 4 org-emphasis-regexp-components) 4)
(defun org-mode-insert-code () (defun org-mode-insert-code ()
(interactive) (interactive)
(org-emphasize ?~))) (org-emphasize ?~)))
#+END_SRC #+END_SRC
** Set default archive location ** Set default archive location
When archiving items in org files, the default ist to crate a separate file named ~<filename>.org_archive~. When archiving items in org files, the default ist to crate a separate file named ~<filename>.org_archive~.
This clutters up my notes folder quite a bit, as I use a lot of separate files with thier respective archives. 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. All archives should be stored in a single ~.archive~ file per directory.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(setq org-archive-location "./.archive::* From %s") (setq org-archive-location "./.archive::* From %s")
#+END_SRC #+END_SRC
** Beautify org-mode ** Beautify org-mode
*** Icons for headline indentation *** Icons for headline indentation
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package org-bullets (use-package org-bullets
:init (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))) :init (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))))
#+END_SRC #+END_SRC
*** Replace checkmark with unicode icons *** Replace checkmark with unicode icons
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package pretty-mode (use-package pretty-mode
:init (global-pretty-mode t)) :init (global-pretty-mode t))
@@ -386,10 +410,10 @@ This is my configuration for the emacs editor.
(push '("[X]" . "" ) prettify-symbols-alist) (push '("[X]" . "" ) prettify-symbols-alist)
(push '("[-]" . "" ) prettify-symbols-alist) (push '("[-]" . "" ) prettify-symbols-alist)
(prettify-symbols-mode))) (prettify-symbols-mode)))
#+END_SRC #+END_SRC
*** Strike out done ckeckbox items *** Strike out done ckeckbox items
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defface org-checkbox-done-text (defface org-checkbox-done-text
'((t (:foreground "#71696A" :strike-through t))) '((t (:foreground "#71696A" :strike-through t)))
"Face for the text part of a checked org-mode checkbox.") "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\\)" `(("^[ \t]*\\(?:[-+*]\\|[0-9]+[).]\\)[ \t]+\\(\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\[\\(?:X\\|\\([0-9]+\\)/\\2\\)\\][^\n]*\n\\)"
1 'org-checkbox-done-text prepend)) 1 'org-checkbox-done-text prepend))
'append) 'append)
#+END_SRC #+END_SRC
** CSS Themes for Exports ** CSS Themes for Exports
When exporting from org-mode (usually to HTML) we want to specify additional styles. When exporting from org-mode (usually to HTML) we want to specify additional styles.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defvar org-theme-css-dir "~/.emacs.d/org-css/") (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. 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. 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. 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. 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 () (defun toggle-org-custom-inline-style ()
(interactive) (interactive)
(let ((hook 'org-export-before-parsing-hook) (let ((hook 'org-export-before-parsing-hook)
@@ -450,11 +474,11 @@ This is my configuration for the emacs editor.
nil) nil)
(message "Set custom style from %s" f)) (message "Set custom style from %s" f))
(message "Custom header file %s doesnt exist"))))) (message "Custom header file %s doesnt exist")))))
#+END_SRC #+END_SRC
** Prettier Timestamps in Exports ** Prettier Timestamps in Exports
The default timestamps look pretty unintuitive, with all the angle brackets and all. Let's make them look better. The default timestamps look pretty unintuitive, with all the angle brackets and all. Let's make them look better.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
;;(add-to-list 'org-export-filter-timestamp-functions ;;(add-to-list 'org-export-filter-timestamp-functions
;; #'endless/filter-timestamp) ;; #'endless/filter-timestamp)
;;(defun endless/filter-timestamp (trans back _comm) ;;(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)) ;; (replace-regexp-in-string "&[lg]t;" "" trans))
;; (`latex ;; (`latex
;; (replace-regexp-in-string "[<>]" "" trans)))) ;; (replace-regexp-in-string "[<>]" "" trans))))
#+END_SRC #+END_SRC
Removed for now, this somehow breaks emacs 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-default org-display-custom-times t)
(setq org-time-stamp-custom-formats (setq org-time-stamp-custom-formats
'("<%a %d.%m.%Y>" . "<%d.%m.%y %H:%M>")) '("<%a %d.%m.%Y>" . "<%d.%m.%y %H:%M>"))
#+END_SRC #+END_SRC
** Templates ** Templates
*** Babel *** Babel
Here we set custom templates to be used for structure expansion. 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". These are used when we type "<" folowed by the shortcut for a template and hit "TAB".
e.g. "<s TAB" expands to ~#+BEGIN_SRC ?\n\n#+END_SRC~ e.g. "<s TAB" expands to ~#+BEGIN_SRC ?\n\n#+END_SRC~
**** emacs-lisp **** emacs-lisp
Shortcut for creating ~emacs-lisp~ code blocks. This is used extensively in this very file. Shortcut for creating ~emacs-lisp~ code blocks. This is used extensively in this very file.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(add-to-list 'org-structure-template-alist '("el" "#+BEGIN_SRC emacs-lisp\n?\n#+END_SRC")) (add-to-list 'org-structure-template-alist '("el" "#+BEGIN_SRC emacs-lisp\n?\n#+END_SRC"))
#+END_SRC #+END_SRC
*** Capture Support Functions *** Capture Support Functions
First we define a function to look the subheading under which we want to file captures: First we define a function to look the subheading under which we want to file captures:
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun org-get-target-headline (&optional targets prompt) (defun org-get-target-headline (&optional targets prompt)
"Prompt for a location in an org file and jump to it. "Prompt for a location in an org file and jump to it.
@@ -503,23 +527,23 @@ This is my configuration for the emacs editor.
(prompt (or prompt "Capture Location"))) (prompt (or prompt "Capture Location")))
(org-refile t nil nil prompt)) (org-refile t nil nil prompt))
) )
#+END_SRC #+END_SRC
*** Org Capture *** Org Capture
Here we define templates we want to use to quickly capture stuff and automatically file them away. Here we define templates we want to use to quickly capture stuff and automatically file them away.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(setq org-capture-templates (setq org-capture-templates
'(("l" "Link" entry (file "~/Notes/links.org") '(("l" "Link" entry (file "~/Notes/links.org")
"* NEW %?\n:PROPERTIES:\n:CREATED: %U\n:END:\n%i\n") "* NEW %?\n:PROPERTIES:\n:CREATED: %U\n:END:\n%i\n")
("t" "Track" table-line (file+function "~/Notes/tracking.org" org-get-target-headline) ("t" "Track" table-line (file+function "~/Notes/tracking.org" org-get-target-headline)
"| %? | |"))) "| %? | |")))
#+END_SRC #+END_SRC
* Treemacs * Treemacs
Treemacs makes navigating folders and files much easier. This is the default config from [[https://github.com/Alexander-Miller/treemacs][the offical repository]] as a base, with slight modifications to suite my config. Treemacs makes navigating folders and files much easier. This is the default config from [[https://github.com/Alexander-Miller/treemacs][the offical repository]] as a base, with slight modifications to suite my config.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package treemacs (use-package treemacs
:defer t :defer t
:init :init
@@ -592,50 +616,50 @@ This is my configuration for the emacs editor.
(use-package treemacs-magit (use-package treemacs-magit
:after treemacs magit :after treemacs magit
:ensure t) :ensure t)
#+END_SRC #+END_SRC
* Additional Package Imports * Additional Package Imports
** All The Icons ** All The Icons
We want to have some nice looking icons We want to have some nice looking icons
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package all-the-icons) (use-package all-the-icons)
#+END_SRC #+END_SRC
** Recentf ** Recentf
Show recent files in the buffer selection Show recent files in the buffer selection
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package recentf (use-package recentf
:init (recentf-mode t) :init (recentf-mode t)
:config :config
(add-to-list 'recentf-exclude "\\.emacs.d") (add-to-list 'recentf-exclude "\\.emacs.d")
(add-to-list 'recentf-exclude ".+tmp......\\.org")) (add-to-list 'recentf-exclude ".+tmp......\\.org"))
#+END_SRC #+END_SRC
** Rainbow Delimiters ** Rainbow Delimiters
We want to have some nicely colored delimiters when reading and writing lisp code We want to have some nicely colored delimiters when reading and writing lisp code
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package rainbow-delimiters (use-package rainbow-delimiters
:hook (prog-mode . rainbow-delimiters-mode)) :hook (prog-mode . rainbow-delimiters-mode))
#+END_SRC #+END_SRC
** Markdown Mode ** Markdown Mode
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package markdown-mode (use-package markdown-mode
:mode ("\\.md$" . gfm-mode) :mode ("\\.md$" . gfm-mode)
:config :config
(when (executable-find "pandoc") (when (executable-find "pandoc")
(setq markdown-command "pandoc -f markdown -t html"))) (setq markdown-command "pandoc -f markdown -t html")))
#+END_SRC #+END_SRC
** Duplicate Thing ** Duplicate Thing
Quick bind to ~C-c u ~ to duplicate the current line Quick bind to ~C-c u ~ to duplicate the current line
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package duplicate-thing (use-package duplicate-thing
:bind (("C-c u" . duplicate-thing))) :bind (("C-c u" . duplicate-thing)))
#+END_SRC #+END_SRC
** Guide Key ** Guide Key
Use this to get some help with key bindings Use this to get some help with key bindings
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package guide-key (use-package guide-key
:diminish guide-key-mode :diminish guide-key-mode
:config :config
@@ -645,33 +669,33 @@ This is my configuration for the emacs editor.
"C-c l" ;; line-jumping "C-c l" ;; line-jumping
"C-c o" "C-c o"
))) )))
#+END_SRC #+END_SRC
** ACE Window ** ACE Window
Small package to quickly switch tiled windows. Small package to quickly switch tiled windows.
Use ~M-p~ to quickly switch. Use ~M-p~ to quickly switch.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package ace-window (use-package ace-window
:bind (("M-o" . 'ace-window))) :bind (("M-o" . 'ace-window)))
#+END_SRC #+END_SRC
** htmlize ** htmlize
HTML Exporter for org-mode HTML Exporter for org-mode
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package htmlize) (use-package htmlize)
#+END_SRC #+END_SRC
** which-key ** which-key
This package provides a minor mode that shows a list of possible keys in the minibuffer. This package provides a minor mode that shows a list of possible keys in the minibuffer.
After a second of inactivity the minibuffer will expand and show possible completions for the started command. After a second of inactivity the minibuffer will expand and show possible completions for the started command.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package which-key (use-package which-key
:config :config
(which-key-mode t)) (which-key-mode t))
#+END_SRC #+END_SRC
* Set Variables * Set Variables
** General Emacs Options ** General Emacs Options
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(setq (setq
compilation-always-kill t ; Never prompt to kill a compilation session. compilation-always-kill t ; Never prompt to kill a compilation session.
compilation-scroll-output 'first-error ; Always scroll to the bottom. compilation-scroll-output 'first-error ; Always scroll to the bottom.
@@ -693,79 +717,79 @@ This is my configuration for the emacs editor.
load-prefer-newer t ; load newest file version available load-prefer-newer t ; load newest file version available
user-full-name "Marcel Fries" ; it's me user-full-name "Marcel Fries" ; it's me
) )
#+END_SRC #+END_SRC
** Read environment variables from the shell ** Read environment variables from the shell
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(use-package exec-path-from-shell (use-package exec-path-from-shell
:config :config
(exec-path-from-shell-initialize)) (exec-path-from-shell-initialize))
#+END_SRC #+END_SRC
** Show the current filename in titlebar ** Show the current filename in titlebar
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(setq frame-title-format (setq frame-title-format
'((:eval user-login-name) "@" (:eval (system-name)) ": " (:eval (if (buffer-file-name) '((:eval user-login-name) "@" (:eval (system-name)) ": " (:eval (if (buffer-file-name)
(abbreviate-file-name (buffer-file-name)) (abbreviate-file-name (buffer-file-name))
"%b")) " [%*]")) "%b")) " [%*]"))
#+END_SRC #+END_SRC
** Default encoding ** Default encoding
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(prefer-coding-system 'utf-8) (prefer-coding-system 'utf-8)
#+END_SRC #+END_SRC
** Shorten "yes or no" questions ** Shorten "yes or no" questions
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defalias 'yes-or-no-p 'y-or-n-p) (defalias 'yes-or-no-p 'y-or-n-p)
#+END_SRC #+END_SRC
** Always highlight the current line ** Always highlight the current line
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(global-hl-line-mode t) (global-hl-line-mode t)
#+END_SRC #+END_SRC
** Always highlight matching braces ** Always highlight matching braces
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(show-paren-mode t) (show-paren-mode t)
#+END_SRC #+END_SRC
** Allow selection override ** Allow selection override
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(delete-selection-mode t) (delete-selection-mode t)
#+END_SRC #+END_SRC
** Behave like a normal text editor ** Behave like a normal text editor
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(cua-mode t) (cua-mode t)
#+END_SRC #+END_SRC
** Remember where we are ** Remember where we are
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(save-place-mode) (save-place-mode)
#+END_SRC #+END_SRC
** Set cursor and indet mode ** Set cursor and indet mode
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(setq-default (setq-default
cursor-type 'bar cursor-type 'bar
indent-tabs-mode nil indent-tabs-mode nil
cursor-in-non-selected-windows nil) cursor-in-non-selected-windows nil)
#+END_SRC #+END_SRC
** Set default column width ** Set default column width
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(set-fill-column 95) (set-fill-column 95)
#+END_SRC #+END_SRC
* Hooks * Hooks
** Remove trailing whitespace on file close ** Remove trailing whitespace on file close
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(add-hook 'before-save-hook 'delete-trailing-whitespace) (add-hook 'before-save-hook 'delete-trailing-whitespace)
#+END_SRC #+END_SRC
** Elisp ** Elisp
Some customization for writing elisp Some customization for writing elisp
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun my-elisp-mode-hook () (defun my-elisp-mode-hook ()
"My elisp customizations." "My elisp customizations."
(electric-pair-mode 1) (electric-pair-mode 1)
@@ -773,10 +797,10 @@ This is my configuration for the emacs editor.
(auto-composition-mode nil)) (auto-composition-mode nil))
(add-hook 'emacs-lisp-mode-hook 'my-elisp-mode-hook) (add-hook 'emacs-lisp-mode-hook 'my-elisp-mode-hook)
#+END_SRC #+END_SRC
* Global Key Bindings * Global Key Bindings
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(bind-key "C-x k" 'kill-buffer-with-prejudice) (bind-key "C-x k" 'kill-buffer-with-prejudice)
(bind-key "C-c 5" 'query-replace-regexp) ;; stupid vestigial binding (bind-key "C-c 5" 'query-replace-regexp) ;; stupid vestigial binding
(bind-key "M-/" 'hippie-expand) (bind-key "M-/" 'hippie-expand)
@@ -793,22 +817,22 @@ This is my configuration for the emacs editor.
(bind-key "C-<" 'beginning-of-buffer) (bind-key "C-<" 'beginning-of-buffer)
(bind-key "C->" 'end-of-buffer) (bind-key "C->" 'end-of-buffer)
(bind-key "C-x C-b" 'ibuffer) ;; buffer-list is not a good default (bind-key "C-x C-b" 'ibuffer) ;; buffer-list is not a good default
#+END_SRC #+END_SRC
** Unbind some default key bindings ** Unbind some default key bindings
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(unbind-key "C-<tab>") ;; prevent switching to tab mode randomly (unbind-key "C-<tab>") ;; prevent switching to tab mode randomly
(unbind-key "C-h n") ;; I have never wanted to see emacs news ever (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-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-d") ;; list-directory is utterly useless given the existence of dired
(unbind-key "C-x C-r") ;; as is find-file-read-only (unbind-key "C-x C-r") ;; as is find-file-read-only
#+END_SRC #+END_SRC
* Load ~custom.el~ * Load ~custom.el~
Load a custom file from the emacs home dir. Load a custom file from the emacs home dir.
This file is specific to the maschine emacs runs on. This file is specific to the maschine emacs runs on.
It conatins customizations and file locations that are maschine dependend. It conatins customizations and file locations that are maschine dependend.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(setq custom-file "~/.emacs.d/custom.el") (setq custom-file "~/.emacs.d/custom.el")
(load custom-file 'noerror) (load custom-file 'noerror)
#+END_SRC #+END_SRC