Skip to content
This repository has been archived by the owner on Sep 10, 2023. It is now read-only.

Latest commit

 

History

History
3389 lines (2594 loc) · 98.2 KB

Emacs.org

File metadata and controls

3389 lines (2594 loc) · 98.2 KB

¬#+title: My Emacs configuration

This document hosts my Emacs configuration, in the style of literate programming, by leveraging Org-Mode.

TODOs

[#A] Organize packages in better categories

[#A] Documentation and commentary need (a lot of) improvement

[#B] Mirror in personal site

[#C] Create dashboard buttons

[#C] Add tree-sitter support

Replace lsp with eglot

Miscellaneous configurations

This section consists of various little configurations and settings that generally improve the quality of life in Emacs. No packages are configured here, only built-in options and variables.

This are just little tweaks to make the Emacs experience more pleasurable.

  • Startup Performance
    ;; -*- lexical-binding: t; -*-
    
    ;; The default is 800 kilobytes.  Measured in bytes.
    (setq gc-cons-threshold (* 50 1000 1000))
    
    ;; Profile emacs startup
    (add-hook 'emacs-startup-hook
              (lambda ()
                (message "*** Emacs loaded in %s seconds with %d garbage collections."
                         (emacs-init-time "%.2f")
                         gcs-done)))
        
  • Native compilation
    ;; Silence compiler warnings as they can be pretty disruptive
    (setq native-comp-async-report-warnings-errors nil)
    
    ;; Set the right directory to store the native comp cache
    (add-to-list 'native-comp-eln-load-path (expand-file-name "eln-cache/" user-emacs-directory))
        
  • Disable package.el
    (setq package-enable-at-startup nil)
        
  • Full name
    (setq user-full-name "Konstantinos Chousos")
        
  • Disables the start-up message of default emacs.
    (setq inhibit-startup-message t)
        
  • Frame sizing
    (add-to-list 'default-frame-alist '(height . 60))
    (add-to-list 'default-frame-alist '(width . 220))
        
  • Remove some visual clutter
    (tool-bar-mode -1)
    ;; (tooltip-mode -1)
    ;; (menu-bar-mode -1)
        
  • Encoding settings
    (set-language-environment "UTF-8")
    (prefer-coding-system 'utf-8)
    (set-default-coding-systems 'utf-8)
        
  • Wrap lines instead of showing only the first 80-something characters and then having to horizontally scroll to view the rest.
    (set-default 'truncate-lines nil)
        
  • Use the system clipboard
    (setq x-select-enable-clipboard t)
        
  • Use view-mode for read-only files
    (setq view-read-only t)
        
  • Disable the “bell” sound
    (setq ring-bell-function #'ignore)
        
  • When asked a yes or no question, just typing y or n will do the trick.
    (defalias 'yes-or-no-p 'y-or-n-p)
        
  • Show column number as well in the modeline
    (setq column-number-mode t)
        
  • Allow resizing
    ;; (setq frame-inhibit-implied-resize t)
        
  • Fringes configuration
    ;; Remove the line-wrap fringe indicators
    (setq-default fringe-indicator-alist (assq-delete-all 'truncation fringe-indicator-alist))
    
    (fringe-mode 10)
        
  • Enable word wrap with whit
    (setq global-word-wrap-whitespace-mode t)
        
  • Blink cursor
    (blink-cursor-mode 1)
        
  • Do not highlight the current line

    This is enabled only in programming modes

    (global-hl-line-mode 0)
        
  • Make Emacs fullscreen by default
    (add-to-list 'default-frame-alist '(fullscreen . maximized))
        
  • Scroll bar configuration
    (global-set-key (kbd "M-<f3>") 'scroll-bar-mode)
    (scroll-bar-mode 0)
    (window-divider-mode 0)
    
    (setq scroll-bar-adjust-thumb-portion t)
    
    (set-window-scroll-bars (minibuffer-window) nil nil nil nil t)
    
    ;; (setq mouse-wheel-scroll-amount '(5 ((shift) . 1)))
    
    (setq mouse-wheel-progressive-speed nil) ;; don't accelerate scrolling
    
    (setq mouse-wheel-follow-mouse 't) ;; scroll window under mouse
    
    (setq scroll-step 1) ;; keyboard scroll one line at a time
    
    (pixel-scroll-precision-mode t)
    
    ;; (setq scroll-conservatively 100)
        
  • Don’t clutter the directory of the current file with backups
    (setq make-backup-files nil)
    (setq auto-save-default nil)
        
  • Tab configuration
    (setq-default indent-tabs-mode nil)
    (setq-default tab-width 4)
    (setq indent-line-function #'insert-tab)
        
  • Enable electric parentheses
    (setq electric-pair-pairs '(
                                (?\{ . ?\})
                                (?\( . ?\))
                                (?\[ . ?\])
                                (?\" . ?\")
                                ))
    (electric-pair-mode t)
    
    ;; (add-hook 'org-mode-hook (lambda ()
    ;;            (setq-local electric-pair-inhibit-predicate
    ;;                    `(lambda (c)
    ;;                   (if (char-equal c ?<) t (,electric-pair-inhibit-predicate c))))))
        
  • Disable line numbers
    (global-display-line-numbers-mode 0)
        
  • When you do show line numbers, show them relative to current line
    (setq display-line-numbers-type 'relative)
        
  • Disable meaningless warnings
    (setq warning-minimum-level :emergency)
        
  • Enable recent files history
    (recentf-mode 1)
    (setq recentf-max-menu-items 25)
    (setq recentf-max-saved-items 25)
    (global-set-key "\C-x\ \C-r" 'recentf-open-files)
    (run-at-time nil (* 5 60) 'recentf-save-list)
        
  • Hides minor modes in modeline.
    (setq-default mode-line-format '("%e" mode-line-front-space
                             (:propertize
                              ("" mode-line-mule-info mode-line-client mode-line-modified mode-line-remote)
                              display
                              (min-width
                               (0.0)))
                             mode-line-frame-identification
                             mode-line-buffer-identification
                             (vc-mode vc-mode)
                             "  "
                             mode-line-position
                             "  "
                             "  "
                             mode-name
                             "  "
                             mode-line-misc-info
                             mode-line-end-spaces))
        
  • When killing a modified buffer, give the option to see the diff <<my kill>>
    (defun my-kill-this-buffer ()
      (interactive)
      (catch 'quit
        (save-window-excursion
          (let (done)
            (when (and buffer-file-name (buffer-modified-p))
              (while (not done)
                (let ((response (read-char-choice
                                 (format "Save file %s? (y, n, d, q) " (buffer-file-name))
                                 '(?y ?n ?d ?q))))
                  (setq done (cond
                              ((eq response ?q) (throw 'quit nil))
                              ((eq response ?y) (save-buffer) t)
                              ((eq response ?n) (set-buffer-modified-p nil) t)
                              ((eq response ?d) (diff-buffer-with-file) nil))))))
            (kill-buffer (current-buffer))))))
    
    
        
  • I-search
    (setq isearch-lazy-count t)
        
  • Auto-revert-mode
    (setq auto-revert-avoid-polling t)
    (global-auto-revert-mode)
        
  • Automatically save bookmarks upon change
    (setq bookmark-save-flag 1)
        
  • Automatically replace selected text upon typing
    (delete-selection-mode 1)
        

Fonts

I dislike Emacs’ default fonts. Since I run Emacs in a daemon/client setup, the following function is needed to correctly apply the custom fonts to every new frame.

  (defun set-font-faces ()
        (message "Setting faces!")
        (set-fontset-font t 'symbol (font-spec :family "Noto Color Emoji" :size 24))
        (set-face-attribute 'default nil :family "Iosevka Kchou" :height 120)
        (set-face-attribute 'fixed-pitch nil :family "Iosevka Kchou" :height 1.0)
        (set-face-attribute 'variable-pitch nil :family "Iosevka Aile"))

(if (daemonp)
    (add-hook 'after-make-frame-functions
              (lambda (frame)
                (with-selected-frame frame
                  (set-font-faces))))
    (set-font-faces))

Line spacing

(setq line-spacing 0.0)

Key-binds

Custom key-binds for built-in functionality of Emacs. Mainly used just to speed things up.

Toggling line numbers

Generally I find line numbers take visual space without giving any valuable information (one exception being programming). Since I use Emacs a lot with prose, I have line numbers disabled. But, if I need them any time there is this keybind.

(global-set-key (kbd "M-<f2>") #'(lambda () (interactive)   (display-line-numbers-mode #'toggle)))

Vertical and horizontal window splits

As the title suggests, this two keybinds split the frame into two windows.

Vertical

(defun split-and-follow-vertically ()
  (interactive)
  (split-window-right)
  (balance-windows)
  (other-window 1))
(global-set-key (kbd "C-x 3") #'split-and-follow-vertically)

Horizontal

(defun split-and-follow-horizontally ()
  (interactive)
  (split-window-below)
  (balance-windows)
  (other-window 1))
(global-set-key (kbd "C-x 2") #'split-and-follow-horizontally)

Toggle Greek and English input methods

Since Greek is my mother tongue, I find myself frequently writing in Greek. So, I need a quick way to toggle the input language without losing all the Emacs keybindings.

(add-hook 'after-init-hook (lambda () (setq default-input-method "greek")))

Kill this buffer

The default behavior of Emacs is to open the buffer list and “kill” the current one by selecting it. This means that to kill the current buffer you must to type C-x k RET.

This way, you can just simply type C-x C-k, that calls the function my-kill-this-buffer (my kill).

(global-set-key (kbd "C-x C-k") #'kill-this-buffer)

WoMan

Open woMan (without man), an emacs native program to read man pages.

(global-set-key (kbd "C-c w") #'woman)

Quick Calc

(global-set-key (kbd "C-x C-8") #'quick-calc)

Packages

This section consists of various packages, built-in or external, that add many extra features.

Package management

elpaca

(defvar elpaca-installer-version 0.5)
(defvar elpaca-directory (expand-file-name "elpaca/" user-emacs-directory))
(defvar elpaca-builds-directory (expand-file-name "builds/" elpaca-directory))
(defvar elpaca-repos-directory (expand-file-name "repos/" elpaca-directory))
(defvar elpaca-order '(elpaca :repo "https://github.com/progfolio/elpaca.git"
                              :ref nil
                              :files (:defaults (:exclude "extensions"))
                              :build (:not elpaca--activate-package)))
(let* ((repo  (expand-file-name "elpaca/" elpaca-repos-directory))
       (build (expand-file-name "elpaca/" elpaca-builds-directory))
       (order (cdr elpaca-order))
       (default-directory repo))
  (add-to-list 'load-path (if (file-exists-p build) build repo))
  (unless (file-exists-p repo)
    (make-directory repo t)
    (when (< emacs-major-version 28) (require 'subr-x))
    (condition-case-unless-debug err
        (if-let ((buffer (pop-to-buffer-same-window "*elpaca-bootstrap*"))
                 ((zerop (call-process "git" nil buffer t "clone"
                                       (plist-get order :repo) repo)))
                 ((zerop (call-process "git" nil buffer t "checkout"
                                       (or (plist-get order :ref) "--"))))
                 (emacs (concat invocation-directory invocation-name))
                 ((zerop (call-process emacs nil buffer nil "-Q" "-L" "." "--batch"
                                       "--eval" "(byte-recompile-directory \".\" 0 'force)")))
                 ((require 'elpaca))
                 ((elpaca-generate-autoloads "elpaca" repo)))
            (progn (message "%s" (buffer-string)) (kill-buffer buffer))
          (error "%s" (with-current-buffer buffer (buffer-string))))
      ((error) (warn "%s" err) (delete-directory repo 'recursive))))
  (unless (require 'elpaca-autoloads nil t)
    (require 'elpaca)
    (elpaca-generate-autoloads "elpaca" repo)
    (load "./elpaca-autoloads")))
(add-hook 'after-init-hook #'elpaca-process-queues)
(elpaca `(,@elpaca-order))

;; Install use-package support
(elpaca elpaca-use-package
  ;; Enable :elpaca use-package keyword.
  (elpaca-use-package-mode)
  ;; Assume :elpaca t unless otherwise specified.
  (setq elpaca-use-package-by-default t))

;; Block until current queue processed.
(elpaca-wait)

Color theme

Since I spend a lot of time inside Emacs, I want to have a good-looking, easy-on-the-eyes color scheme. I also need it to play nice with the other packages on my system and also have a light and dark variant, since I switch between them throughout the day.

Modus themes, developed by Protesilaos Stavrou, are one of the best color schemes for Emacs right now. They became bundled with Emacs, so it isn’t even needed to install anything. They are modular, well documented, easily hackable and robust.

(setq modus-themes-headings
      '((1 . (1.1))
        (2 . (1.075))
        (3 . (1.05))
        (4 . (1.025))
        (t . (1.0))))

(load-theme 'modus-operandi)

(use-package modus-themes
  :elpaca nil
  :init
  ;; Add all your customizations prior to loading the themes
  (setq modus-themes-italic-constructs t
        modus-themes-bold-constructs t
        modus-themes-mixed-fonts t
        modus-themes-subtle-line-numbers t
        modus-themes-deuteranopia nil

        modus-themes-fringes nil ; {nil,'subtle,'intense}

        ;; Options for `modus-themes-mode-line' are either nil, or a list
        ;; that can combine any of `3d' OR `moody', `borderless',
        ;; `accented'.  The variable's doc string shows all possible
        ;; combinations.
        modus-themes-mode-line '(accented borderless)

        ;; Options for `modus-themes-syntax': nil, 'faint,
        ;; 'yellow-comments, 'green-strings,
        ;; 'yellow-comments-green-strings, 'alt-syntax,
        ;; 'alt-syntax-yellow-comments, 'faint-yellow-comments
        modus-themes-syntax '(nil)

        ;; Options for `modus-themes-hl-line': nil, 'intense-background,
        ;; 'accented-background, 'underline-neutral,
        ;; 'underline-accented, 'underline-only-neutral,
        ;; 'underline-only-accented
        modus-themes-hl-line '(accented intense)

        modus-themes-paren-match '(intense) ; {nil,'subtle-bold,'intense,'intense-bold}

        ;; Options for `modus-themes-links': nil, 'faint,
        ;; 'neutral-underline, 'faint-neutral-underline, 'no-underline,
        ;; 'underline-only, 'neutral-underline-only
        modus-themes-links '(nil)

        ;; Options for `modus-themes-prompts' are either nil (the
        ;; default), or a list of properties that may include any of those
        ;; symbols: `background', `bold', `gray', `intense'
        modus-themes-prompts '(intense)

        modus-themes-completions '(intense) ; {nil,'moderate,'opinionated}

        ;; Options for `modus-themes-region': nil, 'no-extend, 'bg-only,
        ;; 'bg-only-no-extend, 'accented, 'accent-no-extend
        modus-themes-region '(accented)

        ;; Options for `modus-themes-diffs': nil, 'desaturated,
        ;; 'bg-only, 'deuteranopia, 'fg-only-deuteranopia
        modus-themes-diffs '(nil)

        org-highlight-latex-and-related '(nil)

        modus-themes-lang-checkers '(intense)

        modus-themes-org-blocks nil; {nil,'gray-background,'tinted-background}

        modus-themes-markup '(intense)
        )
  ;; Load the theme files before enabling a theme
  (modus-themes-load-themes)
  :config
  ;; Load the theme of your choice:
  (modus-themes-load-operandi) ;; OR (modus-themes-load-vivendi)
  :bind ("<f5>" . modus-themes-toggle))

Org

This behemoth of a node contains all my configuration regarding org-mode.

Org

(use-package org
  :elpaca (:repo "/home/kchou/.config/emacs/elpaca/repos/org/" :pin t)
  :commands (org-capture org-agenda)
  :config
  (setq org-hide-emphasis-markers t
        org-ellipsis ""
        org-startup-indented t
        org-pretty-entities nil
        org-footnote-auto-adjust t
        org-support-shift-select t
        org-fontify-whole-heading-line t
        org-fontify-done-headline t
        org-startup-with-inline-images t
        org-fontify-quote-and-verse-blocks t
        org-deadline-warning-days 30
        org-log-done 'time
        org-log-into-drawer t
        org-auto-align-tags nil
        org-tags-column 0
        org-return-follows-link t
        org-agenda-show-outline-path 'title
        org-refile-use-outline-path 'title))

(elpaca-wait)

(add-hook 'org-mode-hook (lambda () (visual-line-mode t)))

(setq org-link-frame-setup '((vm . vm-visit-folder-other-frame)
                             (vm-imap . vm-visit-imap-folder-other-frame)
                             (gnus . org-gnus-no-new-news)
                             (file . find-file)
                             (wl . wl-other-frame)))

(with-eval-after-load 'org
  (add-to-list 'org-modules 'org-habit t))

(setq org-cite-global-bibliography '("/home/kchou/Textfiles/biblio.bib"))

(setq org-image-actual-width (list 700))

(setq org-link-file-path-type 'relative)

Speed commands

(setq org-use-speed-commands t)

Org-Export

Settings regarding the various export features of org-mode.

;; (setq org-export-backends '(texinfo md man beamer latex html ascii))
(setq org-publish-timestamp-directory '"~/.config/emacs/org-timestamps")

This directory contains .csl files, to be used when using the csl backend for exporting citations.

(custom-set-variables
 '(org-cite-csl-styles-dir "/home/kchou/HDD/Έγγραφα/Zotero/styles"))

When exporting to latex, use biblatex as the citation backend, else use csl.

(setq org-cite-export-processors
       '((latex . (biblatex))
         (t . (csl "ieee.csl"))
         ))

HTML Export

Settings for exporting to html.

(setq org-html-validation-link nil)
(setq org-html-head-include-default-style t)
(setq org-html-head-include-scripts t)
(setq org-html-metadata-timestamp-format "%A, %d %b %Y")
(setq org-html-head "<link rel=\"stylesheet\" href=\"/home/kchou/.config/emacs/HTML/worg.css\"/>")
Htmlize

Code highlighting using Emacs when exporting to html.

(use-package htmlize
  :elpaca t)

Org-Reveal

Exporter for Reveal.js.

(use-package ox-reveal
  :elpaca t)

Org-Latex

Settings for when exporting to latex.

(setq org-latex-precompile nil)

(setq org-src-preserve-indentation t)
(setq indent-tabs-mode nil)
(setq org-latex-caption-above '(table))

(add-hook 'org-mode-hook
          '(lambda ()
             (delete '("\\.pdf\\'" . default) org-file-apps)
             (add-to-list 'org-file-apps '("\\.pdf\\'" . "xdg-open %s"))))

;; For syntax highlighting in exported code blocks
;; !!Needs python-pygments installed!!
(setq
 org-latex-listings 'minted
 org-latex-pdf-process
 '("latexmk -f -output-directory=%o %f"))

(setq org-export-with-smart-quotes t)

(setq org-latex-hyperref-template "\\hypersetup{
pdfauthor={%a},
pdftitle={%t},
pdfkeywords={%k},
pdfsubject={%d},
pdfcreator={%c},
pdflang={%L},
colorlinks,
linkcolor=blue,
citecolor=red,
urlcolor=blue}")

(setq org-cite-biblatex-options "[backend=biber, style=ieee, dashed=false]")

org-contrib

Enable some functions from the contrib part of org-mode.

(use-package org-contrib
  :elpaca t
  :init
  (require 'ox-extra)
  (ox-extras-activate '(ignore-headlines)))

Ox-Hugo

Export to markdown files to create a website using Hugo.

(use-package ox-hugo
  :elpaca t
  :after ox)

(setq org-hugo-base-dir (expand-file-name "~/Repos/My repos/Site"))
(setq org-hugo-default-section-directory "posts")
(setq org-hugo-front-matter-format "yaml")
(setq org-hugo-use-code-for-kbd t)

This function exports all org files in a directory—recursively—with ox-hugo.

(defun ox-hugo/export-all (&optional org-files-root-dir dont-recurse)
  "Export all Org files (including nested) under ORG-FILES-ROOT-DIR.

All valid post subtrees in all Org files are exported using
`org-hugo-export-wim-to-md'.

If optional arg ORG-FILES-ROOT-DIR is nil, all Org files in
current buffer's directory are exported.

If optional arg DONT-RECURSE is nil, all Org files in
ORG-FILES-ROOT-DIR in all subdirectories are exported. Else, only
the Org files directly present in the current directory are
exported.  If this function is called interactively with
\\[universal-argument] prefix, DONT-RECURSE is set to non-nil.

Example usage in Emacs Lisp: (ox-hugo/export-all \"~/org\")."
  (interactive)
  (setq org-hugo-base-dir "~/obsid")
  (let* ((org-files-root-dir (or org-files-root-dir default-directory))
         (dont-recurse (or dont-recurse (and current-prefix-arg t)))
         (search-path (file-name-as-directory (expand-file-name org-files-root-dir)))
         (org-files (if dont-recurse
                        (directory-files search-path :full "\.org$")
                      (directory-files-recursively search-path "\.org$")))
         (num-files (length org-files))
         (cnt 1))
    (if (= 0 num-files)
        (message (format "No Org files found in %s" search-path))
      (progn
        (message (format (if dont-recurse
                             "[ox-hugo/export-all] Exporting %d files from %S .."
                           "[ox-hugo/export-all] Exporting %d files recursively from %S ..")
                         num-files search-path))
        (dolist (org-file org-files)
          (with-current-buffer (find-file-noselect org-file)
            (message (format "[ox-hugo/export-all file %d/%d] Exporting %s" cnt num-files org-file))
            (org-hugo-export-wim-to-md :all-subtrees)
            (setq cnt (1+ cnt))))
        (message "Done!")))))

Org Bookmarks

(setq org-bookmark-names-plist '(:last-capture nil :last-refile nil :last-capture-marker nil))

Org-refile

(setq org-refile-targets `((nil :maxlevel . 5)
                           (,(directory-files-recursively "~/Textfiles/Org files/" "^[A-Za-zΑ-Ωα-ω0-9 ]*.org$") :maxlevel . 4)))

(setq org-outline-path-complete-in-steps nil)
(setq org-refile-use-outline-path 'file)

Org-store-link

(global-set-key (kbd "C-c l") #'org-store-link)

Org-Timer

(setq org-clock-sound "~/.config/emacs/clock.wav")

Oxr

Autocomplete for figures in file.

(use-package oxr
  :elpaca (oxr :type git :host github :repo "bdarcus/oxr")
  :bind
  (("C-c r" . oxr-insert-ref)))

org-cite-csl-activate

Render citations in Chicago-style.

;; (use-package citeproc :elpaca t)
(use-package org-cite-csl-activate
  :elpaca (org-cite-csl-activate :type git :host github :repo "andras-simonyi/org-cite-csl-activate")
  :after org
  :init
(add-hook 'org-mode-hook (lambda () (cursor-sensor-mode 1)))

(require 'oc-csl-activate)
(setq org-cite-activate-processor 'csl-activate)

(setq org-cite-csl-activate-use-document-style t)
(setq org-cite-csl-activate-use-document-locale t))

;; (setq org-cite-csl-activate-use-citar-cache t)

Org-Download

Utility to paste screenshots or drag-and-drop images in the org buffer.

(use-package org-download
  :elpaca t)

(setq-default org-download-image-org-width 300
              org-download-heading-lvl nil)

(defun dummy-org-download-annotate-function (link)  "")

(setq-default org-download-annotate-function
              #'dummy-org-download-annotate-function)

(global-set-key (kbd "s-y") #'org-download-clipboard)

Org-Babel

Enables you to execute source blocks in buffer.

Ob-Sagemath

(use-package ob-sagemath
  :elpaca t)

;; Ob-sagemath supports only evaluating with a session.
(setq org-babel-default-header-args:sage '((:session . t)
                                           ;; (:results . "drawer")
                                           ))

;; ;; C-c c for asynchronous evaluating (only for SageMath code blocks).
;; (with-eval-after-load "org"
;;   (define-key org-mode-map (kbd "C-c c") 'ob-sagemath-execute-async))

;; ;; Do not confirm before evaluation
;; (setq org-confirm-babel-evaluate nil)

;; ;; Do not evaluate code blocks when exporting.
;; (setq org-export-babel-evaluate nil)

;; ;; Show images after evaluating code blocks.
;; (add-hook 'org-babel-after-execute-hook 'org-display-inline-images)

Ob-Prolog

(use-package ob-prolog
  :elpaca (:host github :repo "ljos/ob-prolog"))

;; (setq org-babel-prolog-command "eclipse")

emacs-ob-racket

(use-package ob-racket
  :elpaca (:type git :host github :repo "hasu/emacs-ob-racket"))
(elpaca-wait)

ob-mermaid

(use-package ob-mermaid
  :elpaca t
  :config
  (setq ob-mermaid-cli-path "/home/kchou/Repos/Programs/mermaid/node_modules/.bin/mmdc"
        org-babel-default-header-args:mermaid '((:results . "file") (:exports . "results") (:pupeteer-config-file . "/home/kchou/Repos/Programs/mermaid/my-puppeteer-config.json"))))

Global

(elpaca-wait)
(org-babel-do-load-languages
 'org-babel-load-languages
 '((emacs-lisp :tangle ./init.el . t)
   (C . t)
   (python . t)
   (octave . t)
   (R . t)
   (prolog . t)
   (haskell . t)
   (racket . t)
   (mermaid . t)
   ))
;; Show syntax highlighting per language native mode in *.org
(setq org-src-fontify-natively t)
;; For languages with significant whitespace like Python:
(setq org-src-preserve-indentation t)

(setq org-confirm-babel-evaluate nil)

Org-Transclusion

Provides transclusion of other org files.

(use-package org-transclusion
  :elpaca t
  :config
  (add-to-list 'org-transclusion-extensions 'org-transclusion-indent-mode)
  (add-to-list 'org-transclusion-extensions 'org-transclusion-src-lines))

(define-key global-map (kbd "C-c t a") #'org-transclusion-add)
(define-key global-map (kbd "C-c t t") #'org-transclusion-mode)

Org-Plot

Gives the ability to create a plot from data in a org table.

(use-package gnuplot-mode
  :elpaca t)

(use-package gnuplot
  :elpaca t)

Org-Pandoc-Import

(use-package org-pandoc-import
  :elpaca (:host github
             :repo "tecosaur/org-pandoc-import"
             :files ("*.el" "filters" "preprocessors")))

Zotero links

Open zotero:// links from org buffers.

(defun org-zotero-open (path)
  (browse-url-xdg-open (format "zotero:%s" path)))

(with-eval-after-load 'org
  (org-link-set-parameters "zotero" :follow #'org-zotero-open))

Org-Crypt

Allows you to encrypt specific org headings, when tagged with crypt.

(require 'org-crypt)

(with-eval-after-load "org-crypt"
  ;; Automatically encrypts everything that has the tag "crypt"
  ;; when you save the file
  (org-crypt-use-before-save-magic)
  (setq org-tags-exclude-from-inheritance '("crypt"))

  (setq org-crypt-key nil)
  ;; GPG key to use for encryption.
  ;; nil means  use symmetric encryption unconditionally.
  ;; "" means use symmetric encryption unless heading sets CRYPTKEY property.

  (setq auto-save-default nil)
  ;; Auto-saving does not cooperate with org-crypt.el: so you need to
  ;; turn it off if you plan to use org-crypt.el quite often.  Otherwise,
  ;; you'll get an (annoying) message each time you start Org.

  ;; To turn it off only locally, you can insert this:
  ;;
  ;; # -*- buffer-auto-save-file-name: nil; -*-
  )

Org-Web-Tools

Various functions for operations between html and org.

(use-package org-web-tools
  :elpaca (:host github :repo "alphapapa/org-web-tools"))

(global-set-key (kbd "C-x p i") 'org-web-tools-insert-link-for-url)

Org-Pretty-Table-Mode

Prettifies org tables.

(use-package org-pretty-table
  :after org-modern
  :elpaca (:host github :repo "Fuco1/org-pretty-table")
  :hook (org-mode . org-pretty-table-mode))

Org-Modern

Prettifies org files.

(use-package org-modern
  :elpaca t
  :config
  (setq org-modern-table nil)
  (setq org-modern-block-fringe nil)
  ;; (setq org-modern-star '(""))
  :custom
  (org-modern-hide-stars nil) ; adds extra indentation
  :hook
  (org-mode . org-modern-mode)
  (org-agenda-finalize . org-modern-agenda))

Org-Modern-Indent

Makes code blocks pretty.

(use-package org-modern-indent
  :elpaca (:host github :repo "jdtsmith/org-modern-indent")
  :hook
  (org-mode . org-modern-indent-mode))

Org-appear

Org mode provides a way to toggle visibility of hidden elements such as emphasis markers, links, etc. by customising specific variables, e.g., org-hide-emphasis-markers. However, it is currently not possible to do this interactively and on an element-by-element basis. This package, inspired by org-fragtog, enables automatic visibility toggling depending on cursor position. Hidden element parts appear when the cursor enters an element and disappear when it leaves.

(use-package org-appear
  :elpaca t)
(add-hook 'org-mode-hook 'org-appear-mode)
(setq org-appear-trigger 'always)

Org-Remoteimg

This package displays remote images inline in org-mode with automatic caching. The next time you visit the file or fetch the image, it will be instantly fetched from the cache.

(use-package org-remoteimg
  :elpaca (org-remoteimg :type git :host github :repo "gaoDean/org-remoteimg"))

;; optional: set this to wherever you want the cache to be stored
(setq url-cache-directory "~/.cache/emacs/url")

(setq org-display-remote-inline-images 'cache) ;; enable caching

Org-Latex-Preview

This section contains all settings relevant to the overhauled org-latex-preview, written by TEC. It is supposed to become integrated to Org in version 9.7, but until then I use his Org-Mode fork.

(setq-default org-latex-preview-process-alist
      '((dvipng :programs
                ("latex" "dvipng")
                :description "dvi > png" :message "you need to install the programs: latex and dvipng." :image-input-type "dvi" :image-output-type "png" :latex-compiler
                ("%l -interaction nonstopmode -output-directory %o %f")
                :latex-precompiler
                ("%l -output-directory %o -ini -jobname=%b \"&%L\" mylatexformat.ltx %f")
                :image-converter
                ("dvipng --follow -D %D -T tight --depth --height -o %B-%%09d.png %f")
                :transparent-image-converter
                ("dvipng --follow -D %D -T tight -bg Transparent --depth --height -o %B-%%09d.png %f"))
        (dvisvgm :programs
                 ("latex" "dvisvgm")
                 :description "dvi > svg" :message "you need to install the programs: latex and dvisvgm." :image-input-type "dvi" :image-output-type "svg" :latex-compiler
                 ("%l -interaction nonstopmode -output-directory %o %f")
                 :latex-precompiler
                 ("%l -output-directory %o -ini -jobname=%b \"&%L\" mylatexformat.ltx %f")
                 :image-converter
                 ("dvisvgm --page=1- --optimize --clipjoin --relative --no-fonts --bbox=preview -o %B-%%9p.svg %f"))
        (imagemagick :programs
                     ("pdflatex" "convert")
                     :description "pdf > png" :message "you need to install the programs: latex and imagemagick." :image-input-type "pdf" :image-output-type "png" :latex-compiler
                     ("pdflatex -interaction nonstopmode -output-directory %o %f")
                     :latex-precompiler
                     ("pdftex -output-directory %o -ini -jobname=%b \"&pdflatex\" mylatexformat.ltx %f")
                     :image-converter
                     ("convert -density %D -trim -antialias %f -quality 100 %B-%%09d.png"))))

(setq org-latex-compiler "pdflatex"
      org-latex-preview-auto-generate 'live
      org-latex-preview-debounce 0.3
      org-latex-preview-throttle 0.3
      org-latex-preview-persist nil
      org-latex-preview-processing-indicator 'fringe
      org-latex-preview-numbered t
      org-latex-preview-width 1.0
      org-latex-preview-live-display-type 'buffer
      org-latex-preview-default-process 'dvisvgm
      org-startup-with-latex-preview t)

(setq org-latex-default-packages-alist
      '(("AUTO" "inputenc"  t ("pdflatex"))
        ("T1"   "fontenc"   t ("pdflatex"))
        (""     "graphicx"  t)
        (""     "longtable" nil)
        (""     "wrapfig"   nil)
        (""     "rotating"  nil)
        ("normalem" "ulem"  t)
        (""     "amsmath"   t)
        (""     "amssymb"   t)
        (""     "amsfonts"  t)
        (""     "capt-of"   nil)
        (""     "hyperref"  nil)))

(setq org-latex-preview-preamble
      "\\documentclass{article}
[DEFAULT-PACKAGES]
[PACKAGES]
\\usepackage{xcolor}")

(plist-put org-format-latex-options :zoom 1.2) ; Calibrated based on the TeX font and org-buffer font.

(add-hook 'org-mode-hook #'org-latex-preview-auto-mode)

Writing

Olivetti

Centers text in the buffer.

(use-package olivetti
  :elpaca t
  :config
  (setq-default olivetti-body-width 130)
  :hook
  (xeft-mode . olivetti-mode)
  (org-mode . olivetti-mode)
  (markdown-mode . olivetti-mode)
  (Info-mode . olivetti-mode)
  (elpher-mode . olivetti-mode)
  (eww-mode . olivetti-mode)
  (TeX-mode . olivetti-mode)
  (tex-mode . olivetti-mode)
  (LaTeX-mode . olivetti-mode)
  (latex-mode . olivetti-mode))

Unfill

(use-package unfill
  :elpaca t)

Lorem

(use-package lorem-ipsum
  :elpaca t)

Typography

Packages to control fonts, icons and other typographic features of Emacs.

Mixed-Pitch

Allows you to have both variable and fixed pitch fonts depending on the context of the text. For example, normal text is rendered in a variable font, but code in a fixed one.

(use-package mixed-pitch
  :elpaca t
  :hook
  (Info-mode . mixed-pitch-mode)
  (text-mode . mixed-pitch-mode)
  (elpher-mode . mixed-pitch-mode))

(setq mixed-pitch-variable-pitch-cursor nil)
(setq mixed-pitch-set-height nil)

Font ligatures

This package enables font ligatures (if the font supports them).

(use-package ligature
  :elpaca t
  ;; Enable traditional ligature support in eww-mode, if the
  ;; `variable-pitch' face supports it
  :config
  ;; Enable all programming ligatures in programming modes
  (ligature-set-ligatures 'prog-mode '(":::" "::=" "&&" "||" "::" ":=" "==" "!=" ">=" ">>" "<="
                                       "<<" "??" ";;" "->" "<-" "-->" "<--" "=>" "!!" "-->" "<--"
                                       "=<<" "=~" "/=" "++" "--" "===" "<>" "</>" "!==" "</"
                                       ))
  ;; Enables ligature checks globally in all buffers. You can also do it
  ;; per mode with `ligature-mode'.
  (global-ligature-mode t))

All-the-Icons

This is a font that consists of different icons, mainly used to indicate filetypes, programming languages etc.

  • Main package
    (use-package all-the-icons
      :elpaca t)
        
    • Use icons in the mini-buffer
      (use-package all-the-icons-completion
        :elpaca t
        :after (marginalia all-the-icons)
        :hook (marginalia-mode . all-the-icons-completion-marginalia-setup)
        :init
        (all-the-icons-completion-mode))
              

Window and frame handling

This packages are for navigation and handling of buffers, frames and windows.

Winner-mode

Built-in package that saves window states and can cycle through them.

(winner-mode t)

Ace-Window

Move around windows without having to cycle through them.

(global-set-key (kbd "M-o") 'ace-window)
(setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l))
(setq aw-dispatch-always nil)
(setq aw-background nil)
(defvar aw-dispatch-alist
  '((?x aw-delete-window "Delete Window")
    (?m aw-swap-window "Swap Windows")
    (?M aw-move-window "Move Window")
    (?c aw-copy-window "Copy Window")
    (?j aw-switch-buffer-in-window "Select Buffer")
    (?n aw-flip-window)
    (?u aw-switch-buffer-other-window "Switch Buffer Other Window")
    (?c aw-split-window-fair "Split Fair Window")
    (?v aw-split-window-vert "Split Vert Window")
    (?b aw-split-window-horz "Split Horz Window")
    (?o delete-other-windows "Delete Other Windows")
    (?? aw-show-dispatch-help))
  "List of actions for `aw-dispatch-default'.")

(use-package ace-window
  :elpaca t)

Resize-Window

Resize windows with keybinds.

(setq resizewindow-allow-backgrounds nil)
(global-set-key (kbd "C-c C-;") 'resize-window)
(use-package resize-window
  :elpaca t)

Tab-bar

(setq tab-bar-show 1
      tab-bar-auto-width-max '(300 20))

Golden Ratio

(use-package golden-ratio
  :elpaca (:host github :repo "roman/golden-ratio.el")
  :config
  (define-advice select-window (:after (window &optional no-record) golden-ratio-resize-window)
    (golden-ratio)
    nil)
  (golden-ratio-mode 1))

File history

Undo-tree

Default undo/redo doesn’t allow going back to previous “futures”. This package treats file history as a tree and therefore offers much more flexibility.

(use-package undo-tree
  :elpaca t
  :init
  (setq undo-tree-auto-save-history t)

  (defadvice undo-tree-make-history-save-file-name
      (after undo-tree activate)
    (setq ad-return-value (concat ad-return-value ".gz")))

  (setq undo-tree-visualizer-diff t)
  (setq undo-tree-history-directory-alist '(("." . "~/.config/emacs/undo")))

  (global-undo-tree-mode))

Snippets

I use yasnippet to manage my snippets.

Yasnippet

(use-package yasnippet
  :elpaca t
  :config
  (setq yas-snippet-dirs '("~/.config/emacs/snippets"))
  (add-hook 'org-mode-hook  'yas-minor-mode-on)
  (add-hook 'prog-mode-hook 'yas-minor-mode-on)
  (add-hook 'LaTeX-mode-hook 'yas-minor-mode-on))

Yasnippet-Snippets

Includes some default useful snippets.

(use-package yasnippet-snippets
    :elpaca t)

Autocompletion buffer

For this I use corfu. I used company before, but corfu seems faster, more minimal, renders better and uses more built-in features.

Corfu

  (use-package corfu
    :elpaca (:files (:defaults "extensions/*"))

    :custom
    (corfu-cycle t)                       ;; Enable cycling for `corfu-next/previous'
    (corfu-auto t)                        ;; Enable auto completion
    (corfu-separator ?\s)                 ;; Orderless field separator
    (corfu-quit-at-boundary 'separator)   ;; Never quit at completion boundary
    ;; (corfu-quit-no-match nil)          ;; Never quit, even if there is no match
    (corfu-preview-current 'insert)       ;; Disable current candidate preview
    (corfu-preselect 'prompt)             ;; Preselect the prompt
    (corfu-on-exact-match nil)            ;; Configure handling of exact matches
    ;; (corfu-scroll-margin 5)            ;; Use scroll margin
    (corfu-auto-delay 0)
    (corfu-auto-prefix 1)

    (completion-cycle-threshold nil)
    (tab-always-indent 'complete)

    ;; (corfu-min-width 80)
    ;; (corfu-max-width corfu-min-width)

    ;; (lsp-completion-provider :none) ; Use corfu instead the default for lsp completions

    ;; :hook (lsp-completion-mode . kb/corfu-setup-lsp) ; Use corfu for lsp completion

    :config
    ;; Setup lsp to use corfu for lsp completion
    ;; (defun kb/corfu-setup-lsp ()
    ;;   "Use orderless completion style with lsp-capf instead of the
    ;; default lsp-passthrough."
    ;;   (setf (alist-get 'styles (alist-get 'lsp-capf completion-category-defaults))
    ;;         '(orderless)))

    :bind
    (:map corfu-map
          ("C-n" . #'corfu-next)
          ("C-p" . #'corfu-previous)
          ("<escape>" . #'corfu-quit)
          ("<return>" . #'corfu-insert)
          ("<return>" . #'corfu-complete)
          ("C-<tab>" . corfu-insert-separator)
          ("M-h" . #'corfu-popupinfo-documentation)
          ;; ("M-l" . #'corfu-show-location)
          )
          :init
          (global-corfu-mode)
          (corfu-popupinfo-mode))

;; (advice-add #'lsp-completion-at-point :around #'cape-wrap-noninterruptible)

kind-icon

Icons to show for autocompletion items.

(use-package kind-icon
  :elpaca t
  :after corfu
  :custom
  (kind-icon-use-icons t)
  (kind-icon-default-face 'corfu-default) ; Have background color be the same as `corfu' face background
  (kind-icon-blend-background nil)  ; Use midpoint color between foreground and background colors ("blended")?
  (kind-icon-blend-frac 0.08)

  :config
  ;; enable kind-icon only in prog-mode
  (defun my/enable-kind-icon ()
    (setq-local corfu-margin-formatters '(kind-icon-margin-formatter)))
  :hook  ((prog-mode . my/enable-kind-icon))
  )

Cape

Package to manage what completions are enabled.

(use-package cape
  :elpaca t
  ;; ;; Bind dedicated completion commands
  ;; ;; Alternative prefix keys: C-c p, M-p, M-+, ...
  ;; :bind (("C-c p p" . completion-at-point) ;; capf
  ;;        ("C-c p t" . complete-tag)        ;; etags
  ;;        ("C-c p d" . cape-dabbrev)        ;; or dabbrev-completion
  ;;        ("C-c p h" . cape-history)
  ;;        ("C-c p f" . cape-file)
  ;;        ("C-c p k" . cape-keyword)
  ;;        ("C-c p s" . cape-symbol)
  ;;        ("C-c p a" . cape-abbrev)
  ;;        ("C-c p i" . cape-ispell)
  ;;        ("C-c p l" . cape-line)
  ;;        ("C-c p w" . cape-dict)
  ;;        ("C-c p \\" . cape-tex)
  ;;        ("C-c p _" . cape-tex)
  ;;        ("C-c p ^" . cape-tex)
  ;;        ("C-c p &" . cape-sgml)
  ;;        ("C-c p r" . cape-rfc1345))
  :init
  ;; Add `completion-at-point-functions', used by `completion-at-point'.
  (add-to-list 'completion-at-point-functions #'cape-dabbrev)
  ;; (add-to-list 'completion-at-point-functions #'cape-file)
  ;;(add-to-list 'completion-at-point-functions #'cape-history)
  (add-to-list 'completion-at-point-functions #'cape-keyword)
  (add-to-list 'completion-at-point-functions #'cape-tex)
  ;;(add-to-list 'completion-at-point-functions #'cape-sgml)
  ;;(add-to-list 'completion-at-point-functions #'cape-rfc1345)
  (add-to-list 'completion-at-point-functions #'cape-abbrev)
  ;; (add-to-list 'completion-at-point-functions #'cape-ispell)
  ;; (add-to-list 'completion-at-point-functions #'cape-dict)
  ;;(add-to-list 'completion-at-point-functions #'cape-symbol)
  ;; (add-to-list 'completion-at-point-functions #'cape-line)
)

Minibuffer

Vertico

Show candidates as you type.

(use-package vertico
  :elpaca (:files (:defaults "extensions/*"))
  :custom
  (vertico-cycle t)
  :init
  (vertico-mode))

Savehist

Show most recent commands higher.

(use-package savehist
  :elpaca nil
  :init
  (savehist-mode))

Marginalia

Displays a small sentence describing what the command does.

(use-package marginalia
  :after vertico
  :elpaca t
  :custom
  (marginalia-annotators '(marginalia-annotators-heavy marginalia-annotators-light nil))
  :init
  (marginalia-mode))

Orderless

Enables fuzzy searching.

(use-package orderless
  :elpaca t
  :custom
  (completion-styles '(orderless basic))
  (completion-category-overrides '((file (styles basic partial-completion)))))

Shells and terminal emulation

Eshell

Turns eshell’s prompt to a λ.

(setq eshell-prompt-function
      (lambda ()
        (concat
         (propertize "λ " 'face `(:foreground "medium orchid") 'rear-nonsticky t))))

(setq eshell-prompt-regexp "[#λ] ")
(setq eshell-highlight-prompt nil)
(setq eshell-banner-message "\n")

File handling

Web

Eww

Emacs has an awesome built-in browser called EWW (Emacs Web Wowser). Not the greatest name, but it gets the job done.

This makes EWW automatically rename EWW buffers once the page is rendered.

(setq eww-auto-rename-buffer t)

Elpher

A browser for the gemini and gopher protocols.

(use-package elpher
  :elpaca t)

Atomic-Chrome

Used in conjunction with GhostText to edit text areas in my browser with Emacs.

(use-package atomic-chrome
  :elpaca t
  :config
  (atomic-chrome-start-server)
  (setq atomic-chrome-default-major-mode 'org-mode))

Keybinds

Move-Text

(use-package move-text
  :elpaca t)

(global-set-key (kbd "M-S-<up>") 'move-text-line-up)
(global-set-key (kbd "M-S-<down>") 'move-text-line-down)

Shift-number

Allows to change the first number after the cursor on the same line.

(use-package shift-number
  :elpaca t)

(global-set-key (kbd "C-+") 'shift-number-up)
(global-set-key (kbd "C--") 'shift-number-down)

Which-Key

When you start a key-chord and don’t finish it, which-key shows you available keybinds.

(use-package which-key
  :elpaca t
  :init (which-key-mode)
  :diminish which-key-mode
  :config
  (setq which-key-idle-delay 1.5))

Embark

Depending on where the cursor is, embark shows you available actions and displays a keymap with each one matched to a key.

(use-package embark
  :elpaca t

  :bind
  (("C-." . embark-act)         ;; pick some comfortable binding
   ("M-." . embark-dwim)        ;; good alternative: M-.
   ("C-h B" . embark-bindings)) ;; alternative for `describe-bindings'

  :init

  ;; Optionally replace the key help with a completing-read interface
  (setq prefix-help-command #'embark-prefix-help-command)

  :config

  ;; ;; Hide the mode line of the Embark live/completions buffers
  ;; (add-to-list 'display-buffer-alist
  ;;              '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
  ;;                nil
  ;;                (window-parameters (mode-line-format . none))))
  )

Citar-Embark

Integration with the citar package.

(use-package citar-embark
  :elpaca t
  :after citar embark
  :no-require
  :config (citar-embark-mode))

LaTeX

Even though I personally don’t write much latex anymore —since I write my documents in org-mode and if need be I export to latex—, the following configuration is used rarely. But nonetheless, it makes Emacs a powerful latex editor.

;; (elpaca-use-package 'auctex)

(load "auctex.el" nil t t)

(setq-default TeX-master nil)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
;; (setq TeX-command-extra-options "-shell-escape -interaction=nonstopmode")
(setq-default TeX-engine 'luatex)
;; (setq-default TeX-PDF-mode t)
(setq TeX-source-correlate-mode t)
;; (setq TeX-view-program-list '(("Evince" "evince --page-index=%(outpage) %o")))
;; (setq TeX-view-program-selection '((output-pdf "Evince")))
;; Use pdf-tools to open PDF files
(setq TeX-view-program-selection '((output-pdf "PDF Tools"))
      TeX-source-correlate-start-server t)
;; Update PDF buffers after successful LaTeX runs
(add-hook 'TeX-after-compilation-finished-functions
          #'TeX-revert-document-buffer)
(setq font-latex-fontify-script nil)
(add-hook 'LaTeX-mode-hook (lambda () (visual-line-mode t)))
(add-hook 'LaTeX-mode-hook 'prettify-symbols-mode)

AucTeX-LaTeXmk

Adds LatexMk support to AUCTeX.

(use-package auctex-latexmk
  :elpaca t
  :init
  (auctex-latexmk-setup))

RefTeX

A package that helps manage references in tex files.

;; Turn on RefTeX in AUCTeX
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
;; Activate nice interface between RefTeX and AUCTeX
(setq reftex-plug-into-AUCTeX t)

CDLaTeX

Speeds up typing latex. Also works in org-mode.

(use-package cdlatex
  :elpaca t)

(add-hook 'org-mode-hook #'turn-on-org-cdlatex)
(add-hook 'LaTeX-mode-hook #'turn-on-cdlatex)   ; with AUCTeX LaTeX mode
(add-hook 'latex-mode-hook #'turn-on-cdlatex)   ; with Emacs latex mode

(global-set-key (kbd "C-c e") #'cdlatex-environment)

Spell checking

Since I write a lot of prose, spell checking is a must for any text editor.

Jinx

(use-package jinx
  :elpaca t
  :hook (emacs-startup . global-jinx-mode)
  :bind (("M-$" . jinx-correct)
         ("C-M-$" . jinx-languages))
  :config
  (setq jinx-languages "en_US el_GR"))

Dictionary

(global-set-key (kbd "M-#") #'dictionary-lookup-definition)
(setq dictionary-server "dict.org")
;; mandatory, as the dictionary misbehaves!
(setq switch-to-buffer-obey-display-actions t)
(add-to-list 'display-buffer-alist
   '("^\\*Dictionary\\*" display-buffer-in-side-window
     (side . right)
     (window-width . 0.45)))

Bibliography management

Citar

Reads Bibliography from the .bib file that Zotero exports and allows inserting it in org-mode and latex buffers, viewing the associated files, making notes on the entry etc.

      (use-package citar
        :elpaca t
        :after org
        :bind (("C-c b" . citar-insert-citation)
               ;; :map minibuffer-local-map
               ;; ("M-b" . citar-insert-preset)
               )
        :custom
        (citar-bibliography '("~/Textfiles/biblio.bib"))
        :config
          (defvar citar-indicator-files-icons
  (citar-indicator-create
   :symbol (all-the-icons-faicon
            "file-o"
            :face 'all-the-icons-green
            :v-adjust -0.1)
   :function #'citar-has-files
   :padding "  " ; need this because the default padding is too low for these icons
   :tag "has:files"))

(defvar citar-indicator-links-icons
  (citar-indicator-create
   :symbol (all-the-icons-octicon
            "link"
            :face 'all-the-icons-orange
            :v-adjust 0.01)
   :function #'citar-has-links
   :padding "  "
   :tag "has:links"))

(defvar citar-indicator-notes-icons
  (citar-indicator-create
   :symbol (all-the-icons-material
            "speaker_notes"
            :face 'all-the-icons-blue
            :v-adjust -0.3)
   :function #'citar-has-notes
   :padding "  "
   :tag "has:notes"))

(defvar citar-indicator-cited-icons
  (citar-indicator-create
   :symbol (all-the-icons-faicon
            "circle-o"
            :face 'all-the-icon-green)
   :function #'citar-is-cited
   :padding "  "
   :tag "is:cited"))

  (setq citar-indicators
  (list citar-indicator-files-icons
        citar-indicator-links-icons
        citar-indicator-notes-icons
        citar-indicator-cited-icons)))

      ;; (setq citar-symbols
      ;;       `((file ,(all-the-icons-faicon "file-o" :face 'all-the-icons-green :v-adjust -0.1) . " ")
      ;;         (note ,(all-the-icons-material "speaker_notes" :face 'all-the-icons-blue :v-adjust -0.3) . " ")
      ;;         (link ,(all-the-icons-octicon "link" :face 'all-the-icons-orange :v-adjust 0.01) . " ")))
      ;; (setq citar-symbol-separator "  ")

Citar-capf

Adds autocompletion for bibliography entries.

;; (require 'citar-capf)

(add-hook 'completion-at-point-functions
          #'citar-capf
          'append)

Version control

Magit

A front-end for using git. Very powerful, provides complicated actions at the press of a button.

(use-package magit
    :elpaca t
    :commands magit-status)

File management

Dired

Dired is the default file viewer of Emacs. It is very powerful in and of itself, but the following configuration extends its capabilities even more.

(require 'dired)
  (put 'dired-find-alternate-file 'disabled nil)
  (add-hook 'dired-mode-hook (lambda () (hl-line-mode 1)))

Dired-Hide-Dotfiles

Allows you to hide dotfiles in dired by default and toggle them.

(use-package dired-hide-dotfiles
  :elpaca t)

(defun my-dired-mode-hook ()
  "My `dired' mode hook."
  ;; To hide dot-files by default
  (dired-hide-dotfiles-mode))

;; To toggle hiding
(define-key dired-mode-map "." #'dired-hide-dotfiles-mode)
(add-hook 'dired-mode-hook #'my-dired-mode-hook)

Dired-copy-paste

(use-package dired-copy-paste
  :elpaca (dired-copy-paste :type git :host github :repo "jsilve24/dired-copy-paste"))

(define-key dired-mode-map "\C-c\C-x" 'dired-copy-paste-do-cut)
(define-key dired-mode-map "\C-c\C-c" 'dired-copy-paste-do-copy)
(define-key dired-mode-map "\C-c\C-v" 'dired-copy-paste-do-paste)

All the Icons

(use-package all-the-icons-dired
  :elpaca t
  :config
  (add-hook 'dired-mode-hook 'all-the-icons-dired-mode))

Aesthetic enhancements

This part consists of packages that make Emacs prettier.

Dashboard

Provides a start-up welcome screen for Emacs.

(use-package dashboard
  :elpaca t
  :config
  ;; Set the banner
  (setq dashboard-startup-banner 'logo)
  ;; Value can be
  ;; 'official which displays the official emacs logo
  ;; 'logo which displays an alternative emacs logo
  ;; 1, 2 or 3 which displays one of the text banners
  ;; "path/to/your/image.png" or "path/to/your/text.txt" which displays whatever image/text you would prefer
  ;; Content is not centered by default. To center, set
  (setq dashboard-set-navigator t)
  (setq dashboard-center-content t)
  (setq dashboard-banner-logo-title "Welcome to Emacs!")
  (setq dashboard-show-shortcuts nil)
  (setq dashboard-set-heading-icons t)
  (setq dashboard-set-file-icons t)
  (setq dashboard-set-init-info t)
  (setq dashboard-set-footer nil)
  (setq dashboard-week-agenda nil)
  (setq dashboard-page-separator "\n\n")
  (setq dashboard-items '(;;(bookmarks . 20)
                          ;; (projects . 5)
                          ;; (recents . 5)
                          ;; (agenda . 10)
                          ))

  (dashboard-setup-startup-hook))

(setq initial-buffer-choice (lambda () (get-buffer-create "*dashboard*")))

Rainbow-Delimeters

Colors the same color matching delimeters.

(use-package rainbow-delimiters
  :elpaca t
  :hook (prog-mode . rainbow-delimiters-mode))

Telephone Line

(use-package telephone-line
  :elpaca t
  :after (pdf-view)
  :config
  (require 'telephone-line-utils)

  (telephone-line-defsegment telephone-line-pdf-segment ()
    (if (eq major-mode 'pdf-view-mode)
        (propertize (pdf-view-page-number)
                    'face '(:inherit)
                    'display '(raise 0.0)
                    'mouse-face '(:box 1)
                    'local-map (make-mode-line-mouse-map
                                'mouse-1 (lambda ()
                                           (interactive)
                                           (pdf-view-goto-page))))))

  (setq telephone-line-evil-use-short-tag t)
  (telephone-line-defsegment* telephone-line-god-mode-tag-segment ()
    (if god-local-mode
        "N"
      "I"))
  (setq telephone-line-lhs '((nil telephone-line-project-segment)
                             (accent telephone-line-vc-segment telephone-line-erc-modified-channels-segment)
                             (nil telephone-line-buffer-segment telephone-line-process-segment)))

  (setq telephone-line-rhs '((nil telephone-line-flymake-segment telephone-line-misc-info-segment)
                             (accent telephone-line-major-mode-segment)
                             (nil telephone-line-pdf-segment telephone-line-airline-position-segment)
                             ;; (accent telephone-line-god-mode-tag-segment)
                             ))

  (telephone-line-mode 1))

Media consumption

Markdown

(use-package markdown-mode
  :elpaca t)

Typst

(use-package typst-mode
  :elpaca t)

AI

ChatGPT

(use-package gptel
  :elpaca t
  :config
  (setq gptel-default-mode 'org-mode)
  (add-hook 'gptel-mode-hook #'olivetti-mode))

Whisper

For whisper.cpp to compile successfully, add -mavx to the CFLAGS variable in the Makefile.

(use-package whisper
  :elpaca (:host github :repo "natrys/whisper.el")
  :bind ("M-s r" . whisper-run)
  :config
  (setq whisper-install-directory "~/.config/emacs/whisper"
        whisper-model "base"
        whisper-language "el"
        whisper-translate nil))

Documents

PDF-Tools

(use-package pdf-tools
  :elpaca t
  :config
  (setq pdf-misc-print-program-executable "/usr/bin/lpr")

  ;; (setq pdf-view-use-scaling nil)
  (defun my-pdf-tools-backdrop ()
    (face-remap-add-relative
     'default
     `(:background ,(modus-themes-color 'bg-alt))))

  (defun my-pdf-tools-midnight-mode-toggle ()
    (when (derived-mode-p 'pdf-view-mode)
      ;; (if (eq (car custom-enabled-themes) 'modus-vivendi)
      ;;     (pdf-view-midnight-minor-mode 1)
      ;;   (pdf-view-midnight-minor-mode -1))
      (my-pdf-tools-backdrop)))

  (add-hook 'pdf-tools-enabled-hook #'my-pdf-tools-midnight-mode-toggle)
  (add-hook 'modus-themes-after-load-theme-hook #'my-pdf-tools-midnight-mode-toggle)

  (define-pdf-cache-function pagelabels)
  (defun pdf-view-page-number ()
    ;; (interactive)
    ;; (if (called-interactively-p)
    ;; (message "P%s/%s"
    ;;          ;; (nth (1- (pdf-view-current-page))
    ;;          ;;      (pdf-cache-pagelabels))
    ;;          (number-to-string (pdf-view-current-page))
    ;;          (number-to-string (pdf-cache-number-of-pages)))
      (format  "%s of %s"
             ;; (nth (1- (pdf-view-current-page))
             ;;      (pdf-cache-pagelabels))
             (number-to-string (pdf-view-current-page))
             (number-to-string (pdf-cache-number-of-pages))))

  :init
  (pdf-tools-install))

saveplace-pdf-view

(use-package saveplace-pdf-view
  :elpaca t
  :config
  (save-place-mode 1))

Org-PDFTools

(use-package org-pdftools
  :elpaca t
  :hook (org-mode . org-pdftools-setup-link))

Local Variables

With this setting, upon saving this file all the code snippets are tangled to init.el asynchronously and automatically.

(setq enable-local-eval t)