emacs.d

bloated emacs configuration
git clone git://git.ckyln.com/~cem/emacs.d.git
Log | Files | Refs | README

init.org (34111B)


      1 #+TITLE: Emacs Configuration
      2 #+AUTHOR: Cem Keylan
      3 #+BABEL: :cache yes
      4 #+PROPERTY: header-args :tangle yes
      5 #+STARTUP: indent
      6 
      7 This is my emacs configuration file, I used to have a big directory of lisp code
      8 but it became harder to maintain and keep track of. That's why I have created
      9 this org-mode init file. The documentation and the configuration is solely on
     10 this file itself.
     11 
     12 * Intro
     13 ** Table of Contents                                     :TOC_2_gh:noexport:
     14 - [[#intro][Intro]]
     15   - [[#installation-instructions][Installation Instructions]]
     16   - [[#keybindings][Keybindings]]
     17   - [[#ignoring-initel-changes-on-git][Ignoring init.el changes on Git]]
     18   - [[#start-of-the-initel][Start of the init.el]]
     19   - [[#attribution][Attribution]]
     20 - [[#startup-settings][Startup Settings]]
     21   - [[#loading-local-files][Loading local files]]
     22   - [[#declutter][Declutter]]
     23   - [[#package-management][Package management]]
     24   - [[#custom-file][Custom-file]]
     25   - [[#starting-the-server][Starting the server]]
     26   - [[#cheatsheet][cheatsheet]]
     27 - [[#packages][Packages]]
     28   - [[#evil-mode][Evil-mode]]
     29   - [[#org-mode][Org-mode]]
     30   - [[#magit][Magit]]
     31   - [[#flycheck][Flycheck]]
     32   - [[#company-mode][Company Mode]]
     33   - [[#projectile][Projectile]]
     34   - [[#emacs-dashboard][emacs-dashboard]]
     35   - [[#elfeed][elfeed]]
     36   - [[#mu4e][mu4e]]
     37   - [[#helm][helm]]
     38   - [[#academics][Academics]]
     39   - [[#extras][Extras]]
     40 - [[#filetype-configurations][Filetype Configurations]]
     41   - [[#default-formatting][Default Formatting]]
     42   - [[#markdown][Markdown]]
     43   - [[#shell][Shell]]
     44   - [[#python][Python]]
     45   - [[#cc][C/C++]]
     46   - [[#go][Go]]
     47   - [[#makefile][Makefile]]
     48   - [[#latex][LaTeX]]
     49 - [[#themes-and-buffer-customization][Themes and Buffer Customization]]
     50   - [[#doom-themes][Doom themes]]
     51   - [[#all-the-icons][All the icons]]
     52   - [[#buffer-customisation][Buffer customisation]]
     53 - [[#functions][Functions]]
     54   - [[#paste-services][Paste Services]]
     55   - [[#tangle-init][Tangle Init]]
     56 - [[#other-settings][Other Settings]]
     57   - [[#xclip][xclip]]
     58   - [[#shell-commands][shell commands]]
     59   - [[#dired----ls-dired][Dired -- ls dired]]
     60   - [[#coding-system-for-terminal][Coding System for Terminal]]
     61   - [[#backup-options][Backup Options]]
     62   - [[#set-browser][Set Browser]]
     63   - [[#spelling][Spelling]]
     64   - [[#local-init-file][Local init file]]
     65   - [[#end-of-the-file][End of the file]]
     66 
     67 ** Installation Instructions
     68 
     69 If you want to use my emacs configuration, it is pretty simple to get started.
     70 Simply clone the repository and start emacs!
     71 
     72 #+BEGIN_SRC sh :tangle no
     73   # Move your old configuration (if you have one)
     74   mv $HOME/.emacs.d $HOME/.emacs.d.bak
     75 
     76   # Clone the repository
     77   git clone git://git.ckyln.com/emacs.d $HOME/.emacs.d
     78 
     79   # Start emacs
     80   emacs
     81 #+END_SRC
     82 
     83 This will probably take a while, especially because it is setting up for the
     84 first time. You might need to restart emacs after the initial configuration is
     85 done.
     86 
     87 ** Keybindings
     88 
     89 I use cheatsheet to store keybindings that are important to me so I can get them
     90 whenever I need them. You can see those keybindings with the ~C-c s~ global
     91 keybinding.
     92 
     93 ** Ignoring init.el changes on Git
     94 
     95 It can be annoying to see whenever you change your init.org
     96 and see git wanting to update init.el as well. You can avoid
     97 this by doing
     98 
     99 #+BEGIN_SRC sh :tangle no
    100   git update-index --assume-unchanged init.el
    101 #+END_SRC
    102 
    103 ** Start of the init.el
    104 We want lexical binding on init.el and some little commentary.
    105 It would be useful if user decides to read the init.el file instead
    106 of this init.org file.
    107 #+BEGIN_SRC emacs-lisp
    108   ;;; init.el -- Cem Keylan -*- lexical-binding: t; -*-
    109 
    110   ;;; Commentary:
    111   ;;; This file is automatically generated by the init.org document, which
    112   ;;; includes more information about installed packages and usage information.
    113 
    114   ;;; Code:
    115 #+END_SRC
    116 
    117 ** Attribution
    118 I am still relatively new to the emacs environment myself. These are the people
    119 that I have stolen from.
    120 - Bernt Hansen :: I have got lots of org-mode tweaks from Bernt's [[http://doc.norang.ca/org-mode.html][Guide to Org Mode]].
    121 - Adam Schaefers :: While I don't have much code from Adam's Emacs configuration
    122     I was inspired by his passion towards Emacs to make the switch from Vim.
    123     [[https://github.com/a-schaefers/dotfiles/tree/2.0/.emacs.d][Emacs configuration]]
    124 - Gregory J. Stein :: I have learned quite a bit from Greg's blog posts on Emacs.
    125     Check out his own [[https://github.com/gjstein/emacs.d][Emacs configuration]]!
    126 - Lars Tveito :: I was totally inspired from Lars to create an init.org file to
    127     manage my Emacs configuration. [[https://github.com/larstvei/dot-emacs][Emacs configuration]]
    128 
    129 * Startup Settings
    130 
    131 The most important stuff are (for me) is =use-package= and disabling the clutter
    132 as soon as possible. By clutter, I mean bars and menus. Also let's disable the
    133 splash screen.
    134 
    135 ** Loading local files
    136 Personalized customization can be done through =init-local.el= and
    137 =init-preload-local.el=. They must be inside your =~/.emacs.d/lisp= directory.
    138 
    139 Those files must end in the following format.
    140 
    141 #+BEGIN_SRC emacs-lisp :tangle no
    142   ...
    143   (provide 'init-preload-local)
    144 #+END_SRC
    145 
    146 Let's load the =init-preload-local= file if it exists.
    147 
    148 #+BEGIN_SRC emacs-lisp
    149   (add-to-list 'load-path (expand-file-name "lisp" user-emacs-directory))
    150 
    151   (require 'init-preload-local nil t)
    152 #+END_SRC
    153 
    154 ** Declutter
    155 
    156 #+BEGIN_SRC emacs-lisp
    157   (menu-bar-mode 0)
    158   (setq inhibit-splash-screen t)
    159 #+END_SRC
    160 
    161 If you are using emacs-nox, tool-bar-mode (probably) and scroll-bar-mode will
    162 not be defined. This checks if they are defined, and, if they are, will set
    163 them to 0.
    164 
    165 #+BEGIN_SRC emacs-lisp
    166   (when (fboundp 'tool-bar-mode) (tool-bar-mode 0))
    167   (when (fboundp 'scroll-bar-mode) (scroll-bar-mode 0))
    168 #+END_SRC
    169 
    170 ** Package management
    171 
    172 I have switched to straight.el for package management. It is overall faster than
    173 package.el, way more reproducible, and doesn't auto-load packages that you have
    174 installed only for the purpose of trying out. The following is the bootstrapping
    175 script that straight.el uses to install itself.
    176 
    177 #+BEGIN_SRC emacs-lisp
    178   (defvar bootstrap-version)
    179   (let ((bootstrap-file
    180          (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
    181         (bootstrap-version 5))
    182     (unless (file-exists-p bootstrap-file)
    183       (with-current-buffer
    184           (url-retrieve-synchronously
    185            "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
    186            'silent 'inhibit-cookies)
    187         (goto-char (point-max))
    188         (eval-print-last-sexp)))
    189     (load bootstrap-file nil 'nomessage))
    190 
    191   (eval-when-compile
    192   (add-to-list 'load-path (expand-file-name "straight/repos/straight.el" user-emacs-directory)))
    193   (require 'straight)
    194 #+END_SRC
    195 
    196 *** use-package
    197 
    198 We need =use-package= for maintaining other packages. =use-package= is a macro
    199 for configuring and loading packages in a clean, fast, lazy, and a tidy way. It
    200 is not a package manager, but it can interface with other package managers.
    201 
    202 #+BEGIN_SRC emacs-lisp
    203   (straight-use-package 'use-package)
    204   (require 'bind-key)
    205 #+END_SRC
    206 
    207 ** Custom-file
    208 
    209 I don't want emacs setting up custom variables without me noticing. Let's
    210 disable it.
    211 
    212 #+BEGIN_SRC emacs-lisp
    213   (unless (eq system-type 'windows-nt) (setq custom-file "/dev/null"))
    214   (unless custom-file (setq custom-file "~/.trash"))
    215 #+END_SRC
    216 
    217 ** Starting the server
    218 
    219 I used to have an alias for running emacsclient, now I use a tiny script for it.
    220 
    221 #+NAME: emc
    222 #+BEGIN_SRC sh :tangle emc :tangle-mode (identity #o755)
    223   #!/bin/sh
    224 
    225   tty >/dev/null 2>&1 && set -- -nw "$@"
    226   exec emacsclient --alternate-editor='' -c "$@"
    227 #+END_SRC
    228 
    229 You can install the generated emc script by doing
    230 
    231 #+BEGIN_SRC sh :tangle no
    232   install -Dm755 emc ~/.local/bin/emc
    233 #+END_SRC
    234 
    235 #+BEGIN_SRC emacs-lisp
    236   (use-package server
    237     :if window-system
    238     :hook (after-init . server-start))
    239 #+END_SRC
    240 
    241 ** cheatsheet
    242 This is the program I am using to track individual keybindings. We want this to
    243 be loaded as one of the first packages.
    244 
    245 #+BEGIN_SRC emacs-lisp
    246   (use-package cheatsheet
    247     :straight t
    248     :bind ("C-c s c" . cheatsheet-show)
    249     :config
    250     (cheatsheet-add-group 'Common
    251                           '(:key "C-x C-c" :description "leave Emacs")
    252                           '(:key "C-x C-f" :description "find file")
    253                           '(:key "C-x d"   :description "dired"))
    254     (cheatsheet-add-group 'Cheatsheet
    255                           '(:key "C-c s" :description "Open the cheatsheet buffer")
    256                           '(:key "C-q"   :description "exit the cheatsheet buffer")))
    257 #+END_SRC
    258 
    259 * Packages
    260 
    261 Now we can continue by loading our packages, those are listed according to how
    262 important they are to me.
    263 
    264 ** Evil-mode
    265 
    266 I am an old vim user, and I do not want to miss out on the beauty of vim while I
    267 am using Emacs. Let's begin with the evil-mode itself.
    268 
    269 
    270 #+BEGIN_SRC emacs-lisp
    271   (use-package evil
    272     :straight t
    273     :custom
    274     (evil-want-C-u-scroll nil)
    275     (evil-want-keybinding nil)
    276     (evil-want-C-i-jump nil)
    277     :config
    278     (evil-mode 1))
    279 #+END_SRC
    280 
    281 We didn't ask for the keybindings yet, because we are going to get the
    282 =evil-collection= package now.
    283 
    284 #+BEGIN_SRC emacs-lisp
    285   (use-package evil-collection
    286     :requires evil
    287     :after evil
    288     :straight t
    289     :config
    290     (evil-collection-init))
    291 #+END_SRC
    292 
    293 *** evil-surround
    294 
    295 I used to make use of vim-sandwich, but evil-surround will also do the job well
    296 for me.
    297 
    298 #+BEGIN_SRC emacs-lisp
    299   (use-package evil-surround
    300     :requires evil
    301     :after evil
    302     :straight t
    303     :config
    304     (global-evil-surround-mode 1))
    305 #+END_SRC
    306 
    307 ** Org-mode
    308 
    309 Org mode is one of the biggest reasons I am using Emacs, and it is a must for
    310 me. These are my configurations. Starting with the obvious here. I am currently
    311 trying to tweak portions of it from Bernt's configuration. See the [[Attribution]]
    312 section.
    313 
    314 #+BEGIN_SRC emacs-lisp
    315   (use-package org
    316   :straight org-plus-contrib
    317   :functions org-babel-tangle
    318   :after evil
    319   :bind (("C-c l" . org-store-link) ;; See the cheatsheet configuration
    320          ("C-c a" . org-agenda)     ;; if you change the bindings
    321          ("C-c c" . org-capture))
    322   :custom
    323   (org-directory "~/Org/")
    324   (org-default-notes-file "~/Org/refile.org")
    325   (org-agenda-span 'week)
    326   (org-todo-keywords '((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d)")
    327                        (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)" "PHONE" "MEETING")))
    328   (org-use-fast-todo-selection t)
    329   (org-refile-targets '((nil :maxlevel . 9) (org-agenda-files :maxlevel . 9)))
    330   (org-refile-use-outline-path t)
    331   (org-outline-path-complete-in-steps nil)
    332   (org-refile-allow-creating-parent-nodes 'confirm)
    333   (org-todo-keyword-faces
    334         '(("TODO" :foreground "orange red" :weight bold)
    335           ("NEXT" :foreground "cyan" :weight bold)
    336           ("DONE" :foreground "spring green" :weight bold)
    337           ("WAITING" :foreground "orange" :weight bold)
    338           ("HOLD" :foreground "hot pink" :weight bold)
    339           ("CANCELLED" :foreground "spring green" :weight bold)
    340           ("MEETING" :foreground "spring green" :weight bold)
    341           ("PHONE" :foreground "spring green" :weight bold)))
    342   (org-export-backends '(ascii beamer html latex man md groff koma-letter))
    343   :config
    344   (cheatsheet-add-group '"Org-mode Global"
    345                         '(:key "C-c a"           :description "open org-agenda")
    346                         '(:key "C-c c"           :description "open the org-capture buffer")
    347                         '(:key "C-c c"           :description "org store link")
    348                         '(:key "C-c C-w"         :description "refile the current header"))
    349   (cheatsheet-add-group 'Org-mode
    350                         '(:key "C-c C-e"         :description "org-export")
    351                         '(:key "C-c C-o"         :description "follow link"))
    352   )
    353 
    354 #+END_SRC
    355 
    356 *** evil-org
    357 
    358 I am quite serious on this vim stuff now. I want it everywhere.
    359 
    360 #+BEGIN_SRC emacs-lisp
    361   (use-package evil-org
    362     :straight t
    363     :after (evil org)
    364     :functions evil-org-agenda-set-keys
    365     :hook (org-mode . evil-org-mode)
    366     :config
    367     (require 'evil-org-agenda)
    368     (evil-org-agenda-set-keys))
    369 #+END_SRC
    370 
    371 Now that we have initialized those packages, let's configure them some further.
    372 
    373 
    374 *** doct
    375 
    376 DOCT (declarative org capture templates) is a tool for easily managing capture
    377 templates. It makes it much simpler to read and edit templates.
    378 
    379 #+BEGIN_SRC emacs-lisp
    380   (use-package doct
    381     :after org
    382     :straight t
    383     :config
    384     (setq org-capture-templates
    385           (doct '(("todo"
    386                    :keys "t"
    387                    :file "~/Org/refile.org"
    388                    :clock-in t
    389                    :template ("* %{todo-state} %^{Description}"
    390                               ":PROPERTIES:"
    391                               ":Created: %U"
    392                               ":END:" "%?")
    393                    :children (("todo"
    394                                :keys "t"
    395                                :todo-state "TODO")
    396                               ("next"
    397                                :keys "n"
    398                                :todo-state "NEXT")))
    399                   ("note"
    400                    :keys "n"
    401                    :file "~/Org/refile.org"
    402                    :clock-in t
    403                    :template ("* %? :NOTE:"
    404                               "%U"
    405                               "%a"))
    406                   ("phone"
    407                    :keys "p"
    408                    :file "~/Org/refile.org"
    409                    :template ("* PHONE %? :PHONE:" "%U"))
    410                   ("journal"
    411                    :keys "j"
    412                    :file "~/Org/diary.org"
    413                    :datetree t
    414                    :template ("* %?" "%U"))))))
    415 #+END_SRC
    416 
    417 ** Magit
    418 
    419 I like magit, it is quite useful when you don't want to leave emacs and you have
    420 to manually edit hunks for specific commits. I use evil-magit along with it.
    421 
    422 #+BEGIN_SRC emacs-lisp
    423   (use-package magit
    424     :straight t
    425     :bind ("C-x g" . magit-status)
    426     :config
    427     (cheatsheet-add-group 'Magit
    428                           '(:key "C-x g" :description "open Magit status buffer")
    429                           '(:key "s"     :description "stage object on point (can be file or hunk)")
    430                           '(:key "u"     :description "unstage object on point (can be file or hunk)")
    431                           '(:key "c c"   :description "commit")
    432                           '(:key "P u"   :description "push to upstream")
    433                           '(:key "F u"   :description "pull from upstream")
    434                           '(:key "w"     :description "Apply patches")
    435                           '(:key "W"     :description "Create patches"))
    436   )
    437 #+END_SRC
    438 
    439 *** evil-magit
    440 
    441 #+BEGIN_SRC emacs-lisp
    442   (use-package evil-magit
    443     :straight t
    444     :after (evil magit)
    445     :config (evil-magit-init))
    446 #+END_SRC
    447 
    448 *** Forge
    449 
    450 I like being able to interact with PR's and issues on Github from the comfort of
    451 Emacs. Forge is a good one on that. Less web browsing, the better.
    452 
    453 #+BEGIN_SRC emacs-lisp
    454   (use-package forge :straight t :after magit)
    455 #+END_SRC
    456 
    457 ** Flycheck
    458 
    459 I use flycheck for async syntax and error checking. It can be really useful and
    460 adds to the IDE-likeness of Emacs. I find things like these to be really hacky
    461 and buggy on Vim.
    462 
    463 #+BEGIN_SRC emacs-lisp
    464   (use-package flycheck
    465     :straight t
    466     :config
    467     (global-flycheck-mode)
    468     (cheatsheet-add-group '"Syntax Checking"
    469                           '(:key "C-c ! n" :description "navigate to the next error")
    470                           '(:key "C-c ! p" :description "navigate to the previous error")
    471                           '(:key "C-c ! l" :description "list flycheck errors"))
    472   )
    473   (use-package flycheck-pos-tip
    474     :straight t
    475     :hook (flycheck-mode . flycheck-pos-tip-mode))
    476 #+END_SRC
    477 
    478 ** Company Mode
    479 
    480 Company is a tool that I am still very unfamiliar with. I used to
    481 have completion tools on Vim, but I don't understand company that
    482 much yet. Pretty simple config.
    483 
    484 #+BEGIN_SRC emacs-lisp
    485   (use-package company
    486     :straight t
    487     :custom
    488     (company-idle-delay 1)
    489     (company-minimum-prefix-length 1)
    490     :config
    491     (push 'company-capf company-backends)
    492     (global-company-mode 1))
    493 #+END_SRC
    494 
    495 ** Projectile
    496 
    497 Projectile is a great library/tool for project management. It has great
    498 keybindings that executes commands on a project level.
    499 
    500 #+BEGIN_SRC emacs-lisp
    501   (use-package projectile
    502     :straight t
    503     :bind-keymap ("C-c p" . projectile-command-map)
    504     :config (projectile-mode +1)
    505     (cheatsheet-add-group 'Projectile
    506                           '(:key "C-c p"     :description "projectile prefix")
    507                           '(:key "C-c p f"   :description "find file in project")
    508                           '(:key "C-c p p"   :description "switch to project")
    509                           '(:key "C-c p c"   :description "compile project")
    510                           '(:key "C-c p d"   :description "dired in project")
    511                           '(:key "C-c p s g" :description "grep in project"))
    512   )
    513 #+END_SRC
    514 
    515 ** emacs-dashboard
    516 
    517 The dashboard is my default window of choice that provides me a good amount of
    518 information when I startup Emacs.
    519 
    520 #+BEGIN_SRC emacs-lisp
    521   (use-package dashboard
    522     :straight t
    523     :custom
    524     (dashboard-center-content t)
    525     (show-week-agenda-p nil)
    526     (dashboard-set-footer nil)
    527     (initial-buffer-choice (lambda () (get-buffer "*dashboard*")))
    528     (dashboard-items '((agenda . 10)
    529                      (projects . 5)))
    530     :config (dashboard-setup-startup-hook))
    531 #+END_SRC
    532 
    533 ** elfeed
    534 I am using elfeed as my RSS viewer, and I configure it through my org agenda
    535 file with elfeed-org.
    536 
    537 #+BEGIN_SRC emacs-lisp
    538   (use-package elfeed
    539     :straight t
    540     :hook (after-init . elfeed-update)
    541     :bind ("C-x w" . elfeed))
    542 
    543   (use-package elfeed-org
    544     :straight t
    545     :after elfeed
    546     :custom (rmh-elfeed-org-files (list (concat user-emacs-directory "feed.org")))
    547     :config
    548     (elfeed-org)
    549     (cheatsheet-add-group 'elfeed
    550                           '(:key "C-x w" :description "Open elfeed buffer")
    551                           '(:key "gR"    :description "Refresh feeds")
    552                           '(:key "s"     :description "Sort feed")))
    553 #+END_SRC
    554 
    555 ** mu4e
    556 
    557 Using mail on Emacs has lots of advantages for me, as I can export mails to my
    558 agenda along with lots of other nice stuff. Currently, I am writing a wizard for
    559 mu4e (which outputs the following file), but it is in really early steps, and I
    560 still couldn't make it read from the password-store. So sending mails are still
    561 somewhat wonky.
    562 
    563 #+BEGIN_SRC emacs-lisp
    564   (use-package mu4e
    565     :if (executable-find "mu")
    566     :bind (("C-c m c" . mu4e-compose-new)
    567            ("C-c m u" . mu4e)))
    568 #+END_SRC
    569 
    570 ** helm
    571 
    572 Helm is a completion framework that I have adopted recently, and been using
    573 quite frequently. I use it for finding files, manual pages, switching buffers,
    574 and many more.
    575 
    576 #+BEGIN_SRC emacs-lisp
    577   (use-package helm
    578     :straight t
    579     :commands (helm-find-files helm-buffers-list)
    580     :config
    581     (bind-key "M-x"     'helm-M-x)
    582     (bind-key "C-x C-f" 'helm-find-files)
    583     (bind-key "C-c s m" 'helm-man-woman)
    584     (bind-key "C-c s a" 'helm-apropos)
    585     (bind-key "C-x i"   'helm-imenu)
    586     (bind-key "C-x b"   'helm-buffers-list)
    587     (helm-mode 1)
    588     (cheatsheet-add-group 'Helm
    589                           '(:key "C-c s m" :description "Open manual page")
    590                           '(:key "c-c s a" :description "Emacs apropos")
    591                           '(:key "C-x i" :description "helm-imenu")
    592                           '(:key "C-x b" :description "helm-buffers-list")))
    593   (use-package helm-descbinds
    594     :straight t
    595     :config
    596     (bind-key "C-x C-d" 'helm-descbinds)
    597     (cheatsheet-add :group "Helm" :key "C-x C-d" :description "helm-descbinds"))
    598   (use-package helm-swoop     :straight t)
    599 #+END_SRC
    600 
    601 ** Academics
    602 
    603 These are the packages that I make/made use of for academic purposes. These are
    604 the stuff for notetaking, bibliography management, etc.
    605 
    606 *** Org-mode stuff
    607 I am using org-noter and org-roam (which is a zettelkasten) for note-taking, and
    608 I find them extremely useful.
    609 
    610 #+BEGIN_SRC emacs-lisp
    611   (use-package org-noter
    612     :after org
    613     :straight t)
    614 #+END_SRC
    615 
    616 *** Bibliography stuff
    617 I am using helm-bibtex, which is extremely useful navigating bibliography files.
    618 #+BEGIN_SRC emacs-lisp
    619   (use-package helm-bibtex
    620     :straight t)
    621 #+END_SRC
    622 
    623 *** PDF Tools
    624 PDF Tools come handy when I am working with LaTeX, or when I need to take notes
    625 while reading a document. In order to be able to use pdf-tools, you need libpng
    626 and poppler (built with private headers). I have a custom =kiss= build for poppler
    627 that is as follows.
    628 
    629 #+BEGIN_SRC sh :tangle no
    630   #!/bin/sh -e
    631 
    632   export DESTDIR="$1"
    633 
    634   cmake -B build \
    635       -DCMAKE_INSTALL_PREFIX=/usr \
    636       -DCMAKE_INSTALL_LIBDIR=/usr/lib \
    637       -DENABLE_UNSTABLE_API_ABI_HEADERS=ON \
    638       -DENABLE_CPP=ON \
    639       -DENABLE_QT5=OFF \
    640       -DWITH_NSS3=OFF
    641 
    642   cmake --build   build
    643   cmake --install build
    644 #+END_SRC
    645 
    646 #+BEGIN_SRC emacs-lisp
    647   (use-package pdf-tools :straight t)
    648 #+END_SRC
    649 
    650 ** Extras
    651 
    652 These don't really deserve their own sections, but I prefer to use them.
    653 
    654 *** sudo-edit
    655 
    656 This is a package for re-initiating a file as root.
    657 
    658 #+BEGIN_SRC emacs-lisp
    659   (use-package sudo-edit :straight t)
    660 #+END_SRC
    661 
    662 *** linum-relative
    663 I just like seeing the current line number and the relatives of
    664 the other lines.
    665 
    666 #+BEGIN_SRC emacs-lisp
    667   (use-package linum-relative
    668     :straight t
    669     :bind ("C-c r" . display-line-numbers-mode)
    670     :custom
    671     (linum-relative-current-symbol "")
    672     (display-line-numbers-type 'visual)
    673     :hook (prog-mode . display-line-numbers-mode)
    674     :config (cheatsheet-add :group "Common" :key "C-c r" :description "toggle line numbers"))
    675 #+END_SRC
    676 
    677 *** markdown-mode
    678 
    679 I sometimes use this to test the HTML output of markdown documents
    680 that I write.
    681 
    682 #+BEGIN_SRC emacs-lisp
    683   (use-package markdown-mode
    684     :straight t
    685     :config (setq markdown-command "/usr/bin/markdown"))
    686 #+END_SRC
    687 
    688 *** htmlize
    689 
    690 I sometimes output html from org-mode as it comes handy. We use htmlize for
    691 that.
    692 
    693 #+BEGIN_SRC emacs-lisp
    694   (use-package htmlize :straight t)
    695 #+END_SRC
    696 
    697 *** toc-org
    698 
    699 I want to have a basic table-of-contents generation on my org-files
    700 even without exporting the file itself. This is also useful for the
    701 Github README.
    702 
    703 #+BEGIN_SRC emacs-lisp
    704   (use-package toc-org
    705     :straight t
    706     :hook (org-mode . toc-org-mode))
    707 #+END_SRC
    708 
    709 *** which-key
    710 
    711 which-key-mode shows key completions when the user is stuck in a prefix key.
    712 
    713 #+BEGIN_SRC emacs-lisp
    714   (use-package which-key
    715     :straight t
    716     :custom
    717     (which-key-popup-type 'side-window)
    718     :config
    719     (which-key-mode))
    720 #+END_SRC
    721 
    722 *** Treemacs
    723 
    724 #+BEGIN_SRC emacs-lisp
    725   (use-package treemacs
    726     :straight t
    727     :bind ("C-c t" . treemacs))
    728 
    729   (use-package treemacs-all-the-icons
    730     :after (treemacs all-the-icons)
    731     :straight t)
    732 
    733   (use-package treemacs-magit
    734     :after (treemacs magit)
    735     :straight t)
    736 
    737   (use-package treemacs-projectile
    738     :after (treemacs projectile)
    739     :straight t)
    740 
    741   (use-package treemacs-evil
    742     :after (treemacs evil)
    743     :straight t)
    744 #+END_SRC
    745 
    746 * Filetype Configurations
    747 
    748 I would like to have some different configurations for filetypes. Those are for
    749 indents and spaces, mostly. I also like to keep packages specific to stay in
    750 their respective categories.
    751 
    752 ** Default Formatting
    753 
    754 Here is the default formatting for most files. I don't like tabs as indents
    755 so I avoid them wherever I can.
    756 
    757 #+BEGIN_SRC emacs-lisp
    758   (setq-default indent-tabs-mode nil
    759                 tab-width 8
    760                 fill-column 80)
    761 #+END_SRC
    762 
    763 I am using column number mode to keep track of line status.
    764 
    765 #+BEGIN_SRC emacs-lisp
    766   (add-hook 'prog-mode-hook 'column-number-mode)
    767 #+END_SRC
    768 
    769 Electric-pair-mode (which is a built-in), matches parentheses on Emacs. While
    770 I know that this doesn't form a healthy habit, I really like to have such a
    771 function available to me.
    772 
    773 #+BEGIN_SRC emacs-lisp
    774   (electric-pair-mode t)
    775 #+END_SRC
    776 
    777 
    778 For some reason, Emacs doesn't deal with trailing whitespace unless you tell it
    779 to do so. Let's set it so that Emacs will show trailing whitespace on the buffer
    780 and automatically deletes them before save.
    781 
    782 #+BEGIN_SRC emacs-lisp
    783   (setq-default show-trailing-whitespace nil)
    784   (add-hook 'before-save-hook 'delete-trailing-whitespace)
    785 #+END_SRC
    786 
    787 ** Markdown
    788 
    789 For markdown, I want to have 4 spaces as an indentation.
    790 
    791 #+BEGIN_SRC emacs-lisp
    792   (use-package markdown-mode
    793     :straight t
    794     :custom
    795     (md-indent-tabs-mode nil)
    796     (md-tab-width 4))
    797 #+END_SRC
    798 
    799 ** Shell
    800 
    801 For shell, I want to have 4 spaces as an indentation.
    802 
    803 #+BEGIN_SRC emacs-lisp
    804   (use-package sh-script
    805     :custom
    806     (sh-tab-width 4)
    807     (sh-indent-tabs-mode nil))
    808 #+END_SRC
    809 
    810 ** Python
    811 I use the django framework quite frequently at work. So I want a few packages
    812 for that as well.
    813 
    814 *** Company jedi
    815 Company jedi is for better completion while I am editing python files. Here
    816 is the use-package
    817 
    818 #+BEGIN_SRC emacs-lisp
    819   (use-package company-jedi
    820     :straight t
    821     :after company
    822     :init
    823     (add-to-list 'company-backends 'company-jedi))
    824 #+END_SRC
    825 
    826 ** C/C++
    827 
    828 I am trying to get on with the [[https://www.kernel.org/doc/Documentation/process/coding-style.rst][Kernel Style guide]].
    829 
    830 #+BEGIN_SRC emacs-lisp
    831   (use-package cc-mode
    832     :init
    833     (defun my-c-hook()
    834       "Set indentation size for C."
    835       (setq indent-tabs-mode t)
    836       (setq c-basic-offset tab-width))
    837     (add-hook 'c-mode-hook 'my-c-hook))
    838 #+END_SRC
    839 
    840 *** Irony-mode
    841 I use irony-mode for syntax-checking and completion for C. It can also be used
    842 in conjunction with C++, but I personally don't need it. You can add a hook for
    843 C++ as well in your [[file:lisp/init-local.el][personal configuration]].
    844 
    845 #+BEGIN_SRC emacs-lisp :tangle no
    846   (add-hook 'c++-mode-hook 'irony-mode)
    847 #+END_SRC
    848 
    849 
    850 This installs =irony=, =company-irony=, and =flycheck-irony=.
    851 
    852 #+BEGIN_SRC emacs-lisp
    853   (use-package irony
    854     :straight t
    855     :hook (c-mode . irony-mode))
    856 
    857   (use-package flycheck-irony
    858     :straight t
    859     :after (flycheck irony)
    860     :hook (flycheck-mode . flycheck-irony-setup))
    861 
    862   (use-package company-irony
    863     :straight t
    864     :after (company irony)
    865     :config
    866     (add-to-list 'company-backends 'company-irony))
    867 #+END_SRC
    868 
    869 ** Go
    870 
    871 For Go, we are installing =go-mode= and =company-go=. =go-mode= is a rewrite of
    872 the built-in major mode for go. =company-go= is the company backend for go.
    873 
    874 #+BEGIN_SRC emacs-lisp
    875   (use-package go-mode :straight t)
    876   (use-package company-go
    877     :straight t
    878     :after company
    879   )
    880 #+END_SRC
    881 
    882 ** Makefile
    883 #+BEGIN_SRC emacs-lisp
    884   (use-package helm-make :straight t)
    885 #+END_SRC
    886 
    887 ** LaTeX
    888 
    889 I personally use LaTeX for academic papers, but I don't have some advanced
    890 configuration on it.
    891 
    892 #+BEGIN_SRC emacs-lisp :tangle no
    893   (use-package auctex
    894     :straight t)
    895 #+END_SRC
    896 
    897 * Themes and Buffer Customization
    898 I used to make use of my Xresources themes, but I sometimes sadly
    899 need windows, and I actually do want some eye candy from time to
    900 time.
    901 
    902 ** Doom themes
    903 I want to use the default doom-theme (perhaps I can switch to
    904 Dracula someday as well).
    905 
    906 The 'if' statement makes sure we have
    907 
    908 #+BEGIN_SRC emacs-lisp
    909   (use-package doom-themes
    910     :after all-the-icons
    911     :straight t
    912     :functions doom-themes-org-config doom-themes-treemacs-config
    913     :custom
    914     (doom-themes-enable-bold t)
    915     (doom-themes-enable-italic t)
    916     (doom-themes-treemacs-theme "doom-colors")
    917     :config
    918     (load-theme 'doom-vibrant t)
    919     (doom-themes-treemacs-config)
    920     (doom-themes-org-config))
    921 #+END_SRC
    922 
    923 ** All the icons
    924 
    925 All the icons is an icon-pack. I mean it probably isn't hard to
    926 guess. Pretty straightforward.
    927 
    928 #+BEGIN_SRC emacs-lisp
    929   (use-package all-the-icons
    930     :straight t)
    931 
    932   (use-package all-the-icons-dired
    933     :straight t
    934     :after all-the-icons
    935     :hook (dired-mode . all-the-icons-dired-mode))
    936 #+END_SRC
    937 
    938 ** Buffer customisation
    939 *** Modeline
    940 #+BEGIN_SRC emacs-lisp
    941   (use-package doom-modeline
    942     :straight t
    943     :config (doom-modeline-mode 1))
    944 #+END_SRC
    945 
    946 *** undo-tree
    947 
    948 =undo-tree= provides a nice-looking UI for crawling the buffer history in a
    949 visual tree. While this is already a dependency for some packages here, I wanted
    950 to specify it anyway. I don't use it frequently, but this is one of the packages
    951 that you appreciate having when its time comes.
    952 
    953 #+BEGIN_SRC emacs-lisp
    954   (use-package undo-tree
    955     :straight t
    956     :config
    957     (cheatsheet-add :group "Common" :key "C-x u" :description "undo-tree"))
    958 #+END_SRC
    959 
    960 *** Highlighting TODO
    961 I want to highlight TODO keywords, so I can continue ignoring them in a prettier
    962 way. :)
    963 
    964 #+BEGIN_SRC emacs-lisp
    965   (use-package hl-todo
    966     :straight t
    967     :hook (prog-mode . hl-todo-mode))
    968 #+END_SRC
    969 
    970 * Functions
    971 ** Paste Services
    972 Here are two paste-thingies that I use. I got the first code from
    973 [[https://github.com/a-schaefers/dotfiles/blob/2.0/.emacs.d/lisp.d/termbin.el][@a-schaefer's termbin.el]].
    974 #+BEGIN_SRC emacs-lisp
    975   ;; termbin.el
    976   (defun region-to-termbin (start end)
    977     "Push the marked region (START to END) to termbin.com via shell command."
    978     (interactive "r")
    979     (message "pushing region to termbin.com...")
    980     (shell-command-on-region start end "nc termbin.com 9999"))
    981 
    982   (defun buffer-to-termbin ()
    983     "Push the buffer to termbin.com via shell command."
    984     (interactive)
    985     (message "pushing buffer to termbin.com...")
    986     (shell-command-on-region (point-min) (point-max) "nc termbin.com 9999"))
    987 
    988   ;; pastesrv.el
    989   (defun region-to-srv (start end)
    990     "Push the marked region (START to END) to server via shell command."
    991     (interactive "r")
    992     (message "pushing region to server...")
    993     (shell-command-on-region start end (concat "pastesrv " (read-string "Enter file name (optional): "))))
    994 
    995   (defun buffer-to-srv ()
    996     "Push the buffer to server via shell command."
    997     (interactive)
    998     (message "pushing buffer to server...")
    999     (shell-command-on-region (point-min) (point-max) (concat "pastesrv " (read-string "Enter file name (optional): "))))
   1000 
   1001   (global-set-key (kbd "C-x p r") 'region-to-srv)
   1002   (global-set-key (kbd "C-x p b") 'buffer-to-srv)
   1003 
   1004   (cheatsheet-add-group 'Common
   1005                         '(:key "C-x p r" :description "Push the current region to server")
   1006                         '(:key "C-x p b" :description "Push the buffer to server"))
   1007 #+END_SRC
   1008 *** Pastesrv
   1009 This is the simple shell script I use to paste to my server. It
   1010 is taken from [[https://codemadness.org/paste-service.html][Hiltjo's blog post]]. I use it as a script rather than
   1011 a shell function so that I can use it with Emacs.
   1012 #+BEGIN_SRC sh :tangle no
   1013   #!/bin/sh
   1014 
   1015   # This substitutes a random 4-character string if no file
   1016   # name is given.
   1017   file="${1:-$(tr -dc "A-Z-a-z-0-9" < /dev/urandom | dd ibs=1 obs=1 count=4 2>/dev/null)}"
   1018 
   1019   # shellcheck disable=2029
   1020   ssh user@ckyln.com "cat > /home/www/ckyln.com/files/$file"
   1021   printf '%s\n' "https://ckyln.com/files/$file"
   1022 #+END_SRC
   1023 ** Tangle Init
   1024 
   1025 To load init.el properly we run a function such as this. This
   1026 function generates init.el from the source blocks inside this
   1027 file using ~org-babel-tangle~ and byte compiles it into ~init.elc~.
   1028 After defining the function, we add an ~after-save-hook~ so
   1029 that the file is generated everytime we save init.org.
   1030 
   1031 #+BEGIN_SRC emacs-lisp
   1032   (defun tangle-init ()
   1033     "Tangles the init.org file, and byte compiles it."
   1034     (when (equal (buffer-file-name)
   1035                  (expand-file-name (concat user-emacs-directory "init.org")))
   1036       (let ((prog-mode-hook nil))
   1037         (org-babel-tangle)
   1038         (byte-compile-file (concat user-emacs-directory "init.el")))))
   1039 
   1040   (add-hook 'after-save-hook 'tangle-init)
   1041 #+END_SRC
   1042 
   1043 * Other Settings
   1044 
   1045 Those are small settings for emacs that I cannot categorize but have importance
   1046 for me.
   1047 
   1048 ** xclip
   1049 
   1050 On the terminal, Emacs doesn't have xclip support. I don't like the
   1051 inconsistency of switching between terminal and the graphical Emacs.
   1052 
   1053 #+BEGIN_SRC emacs-lisp
   1054   (use-package xclip
   1055     :if (executable-find "xclip")
   1056     :if (getenv "DISPLAY")
   1057     :unless (eq system-type 'windows-nt)
   1058     :straight t
   1059     :config (xclip-mode))
   1060 #+END_SRC
   1061 
   1062 ** shell commands
   1063 
   1064 Typing =M-!= isn't really possible when I am on dwm, so I bind =C-q= for
   1065 executing shell commands. I usually prefix shell commands with =C-u= so that I
   1066 can easily insert text into buffer.
   1067 
   1068 #+BEGIN_SRC emacs-lisp
   1069   (bind-key "C-q" 'shell-command)
   1070 #+END_SRC
   1071 
   1072 ** Dired -- ls dired
   1073 
   1074 I use suckless.org's =sbase= as my coreutils. The =ls= program that I use does
   1075 not have a =--dired= option. Let's disable it.
   1076 
   1077 #+BEGIN_SRC emacs-lisp
   1078   (use-package dired-explorer
   1079     :straight t
   1080     :custom (dired-use-ls-dired nil))
   1081 #+END_SRC
   1082 
   1083 ** Coding System for Terminal
   1084    I want emacs to use utf-8 so my terminal isn't filled with '?' characters.
   1085 #+BEGIN_SRC emacs-lisp
   1086   (set-terminal-coding-system 'utf-8)
   1087 #+END_SRC
   1088 
   1089 ** Backup Options
   1090 
   1091 #+BEGIN_SRC emacs-lisp
   1092   (setq backup-directory-alist `(("." . "~/.cache/emacs/saves")))
   1093 #+END_SRC
   1094 
   1095 ** Set Browser
   1096 
   1097 I am setting the default browser from the BROWSER environment variable
   1098 so that I don't have to keep track of it in case I ever change my browser.
   1099 
   1100 #+BEGIN_SRC emacs-lisp
   1101   (use-package browse-url
   1102     :if (getenv "BROWSER")
   1103     :custom
   1104     (browse-url-generic-program (executable-find (getenv "BROWSER")))
   1105     (browse-url-browser-function 'browse-url-generic))
   1106 #+END_SRC
   1107 
   1108 ** Spelling
   1109 
   1110 As a person who constantly writes documents, spelling is an important part of
   1111 the day, huh?
   1112 
   1113 #+BEGIN_SRC emacs-lisp
   1114   (use-package flyspell
   1115     :if (executable-find "aspell")
   1116     :bind (("C-c i r" . flyspell-region)
   1117            ("C-c i b" . flyspell-buffer)
   1118            ("C-c i m" . flyspell-mode))
   1119     :hook (text-mode . flyspell-mode))
   1120 
   1121   (use-package ispell
   1122     :if (executable-find "aspell")
   1123     :bind ("C-c i c" . ispell-change-dictionary)
   1124     :custom
   1125     (ispell-program-name (executable-find "aspell"))
   1126     (ispell-list-command "--list"))
   1127 #+END_SRC
   1128 
   1129 ** Local init file
   1130 Now that all of this is done, we can load user's personal configuration
   1131 
   1132 #+BEGIN_SRC emacs-lisp
   1133   (require 'init-local nil t)
   1134 #+END_SRC
   1135 
   1136 ** End of the file
   1137 #+BEGIN_SRC emacs-lisp
   1138   (provide 'init)
   1139   ;;; init.el ends here
   1140 #+END_SRC