init.org (35257B)
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 texinfo 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 *** doct 374 375 DOCT (declarative org capture templates) is a tool for easily managing capture 376 templates. It makes it much simpler to read and edit templates. 377 378 #+BEGIN_SRC emacs-lisp 379 (use-package doct 380 :after org 381 :straight t 382 :config 383 (setq org-capture-templates 384 (doct '(("todo" 385 :keys "t" 386 :file "~/org/refile.org" 387 :clock-in t 388 :template ("* %{todo-state} %^{Description}" 389 ":PROPERTIES:" 390 ":Created: %U" 391 ":END:" "%?") 392 :children (("todo" 393 :keys "t" 394 :todo-state "TODO") 395 ("next" 396 :keys "n" 397 :todo-state "NEXT"))) 398 ("note" 399 :keys "n" 400 :file "~/org/refile.org" 401 :clock-in t 402 :template ("* %? :NOTE:" 403 "%U" 404 "%a")) 405 ("phone" 406 :keys "p" 407 :file "~/org/refile.org" 408 :template ("* PHONE %? :PHONE:" "%U")) 409 ("journal" 410 :keys "j" 411 :file "~/org/diary.org" 412 :datetree t 413 :template ("* %?" "%U")) 414 ("recipe" 415 :keys "r" 416 :file "~/org/recipe.org" 417 :template ("* %^{Recipe}" 418 ":PROPERTIES:" 419 ":Created: %U" 420 ":END:" "%?" 421 "** Ingredients" 422 "** Instructions")))))) 423 #+END_SRC 424 425 *** gkroam 426 427 #+BEGIN_SRC emacs-lisp 428 (use-package gkroam 429 :straight t 430 :custom 431 (gkroam-root-dir "~/org/roam") 432 (gkroam-prettify-p t) 433 (gkroam-show-brackets-p t) 434 (gkroam-use-default-filename t) 435 (gkroam-window-margin 4) 436 :bind 437 (("C-c r I" . gkroam-index) 438 ("C-c r d" . gkroam-daily) 439 ("C-c r f" . gkroam-find) 440 ("C-c r i" . gkroam-insert) 441 ("C-c r c" . gkroam-capture) 442 ("C-c r e" . gkroam-link-edit) 443 ("C-c r n" . gkroam-smart-new) 444 ("C-c r p" . gkroam-toggle-prettify) 445 ("C-c r t" . gkroam-toggle-brackets) 446 ("C-c r D" . gkroam-toggle-dynamic) 447 ("C-c r g" . gkroam-update))) 448 #+END_SRC 449 450 ** Magit 451 452 I like magit, it is quite useful when you don't want to leave emacs and you have 453 to manually edit hunks for specific commits. I use evil-magit along with it. 454 455 #+BEGIN_SRC emacs-lisp 456 (use-package magit 457 :straight t 458 :bind ("C-x g" . magit-status) 459 :config 460 (cheatsheet-add-group 'Magit 461 '(:key "C-x g" :description "open Magit status buffer") 462 '(:key "s" :description "stage object on point (can be file or hunk)") 463 '(:key "u" :description "unstage object on point (can be file or hunk)") 464 '(:key "c c" :description "commit") 465 '(:key "P u" :description "push to upstream") 466 '(:key "F u" :description "pull from upstream") 467 '(:key "w" :description "Apply patches") 468 '(:key "W" :description "Create patches")) 469 ) 470 #+END_SRC 471 472 *** evil-magit 473 474 #+BEGIN_SRC emacs-lisp 475 (use-package evil-magit 476 :straight t 477 :after (evil magit) 478 :config (evil-magit-init)) 479 #+END_SRC 480 481 *** Forge 482 483 I like being able to interact with PR's and issues on Github from the comfort of 484 Emacs. Forge is a good one on that. Less web browsing, the better. 485 486 #+BEGIN_SRC emacs-lisp 487 (use-package forge :straight t :after magit) 488 #+END_SRC 489 490 ** Flycheck 491 492 I use flycheck for async syntax and error checking. It can be really useful and 493 adds to the IDE-likeness of Emacs. I find things like these to be really hacky 494 and buggy on Vim. 495 496 #+BEGIN_SRC emacs-lisp 497 (use-package flycheck 498 :straight t 499 :config 500 (global-flycheck-mode) 501 (cheatsheet-add-group '"Syntax Checking" 502 '(:key "C-c ! n" :description "navigate to the next error") 503 '(:key "C-c ! p" :description "navigate to the previous error") 504 '(:key "C-c ! l" :description "list flycheck errors")) 505 ) 506 (use-package flycheck-pos-tip 507 :straight t 508 :hook (flycheck-mode . flycheck-pos-tip-mode)) 509 #+END_SRC 510 511 ** Company Mode 512 513 Company is a tool that I am still very unfamiliar with. I used to 514 have completion tools on Vim, but I don't understand company that 515 much yet. Pretty simple config. 516 517 #+BEGIN_SRC emacs-lisp 518 (use-package company 519 :straight t 520 :custom 521 (company-idle-delay 1) 522 (company-minimum-prefix-length 1) 523 :config 524 (push 'company-capf company-backends) 525 (global-company-mode 1)) 526 #+END_SRC 527 528 ** Projectile 529 530 Projectile is a great library/tool for project management. It has great 531 keybindings that executes commands on a project level. 532 533 #+BEGIN_SRC emacs-lisp 534 (use-package projectile 535 :straight t 536 :bind-keymap ("C-c p" . projectile-command-map) 537 :config (projectile-mode +1) 538 (cheatsheet-add-group 'Projectile 539 '(:key "C-c p" :description "projectile prefix") 540 '(:key "C-c p f" :description "find file in project") 541 '(:key "C-c p p" :description "switch to project") 542 '(:key "C-c p c" :description "compile project") 543 '(:key "C-c p d" :description "dired in project") 544 '(:key "C-c p s g" :description "grep in project")) 545 ) 546 #+END_SRC 547 548 ** emacs-dashboard 549 550 The dashboard is my default window of choice that provides me a good amount of 551 information when I startup Emacs. 552 553 #+BEGIN_SRC emacs-lisp 554 (use-package dashboard 555 :straight t 556 :custom 557 (dashboard-center-content t) 558 (show-week-agenda-p nil) 559 (dashboard-set-footer nil) 560 (initial-buffer-choice (lambda () (get-buffer "*dashboard*"))) 561 (dashboard-items '((agenda . 10) 562 (projects . 5))) 563 :config (dashboard-setup-startup-hook)) 564 #+END_SRC 565 566 ** elfeed 567 I am using elfeed as my RSS viewer, and I configure it through my org agenda 568 file with elfeed-org. 569 570 #+BEGIN_SRC emacs-lisp 571 (use-package elfeed 572 :straight t 573 :hook (after-init . elfeed-update) 574 :bind ("C-x w" . elfeed)) 575 576 (use-package elfeed-org 577 :straight t 578 :after elfeed 579 :custom (rmh-elfeed-org-files (list (concat user-emacs-directory "feed.org"))) 580 :config 581 (elfeed-org) 582 (cheatsheet-add-group 'elfeed 583 '(:key "C-x w" :description "Open elfeed buffer") 584 '(:key "gR" :description "Refresh feeds") 585 '(:key "s" :description "Sort feed"))) 586 #+END_SRC 587 588 ** mu4e 589 590 Using mail on Emacs has lots of advantages for me, as I can export mails to my 591 agenda along with lots of other nice stuff. Currently, I am writing a wizard for 592 mu4e (which outputs the following file), but it is in really early steps, and I 593 still couldn't make it read from the password-store. So sending mails are still 594 somewhat wonky. 595 596 #+BEGIN_SRC emacs-lisp 597 (use-package mu4e 598 :if (executable-find "mu") 599 :bind (("C-c m c" . mu4e-compose-new) 600 ("C-c m u" . mu4e))) 601 #+END_SRC 602 603 ** helm 604 605 Helm is a completion framework that I have adopted recently, and been using 606 quite frequently. I use it for finding files, manual pages, switching buffers, 607 and many more. 608 609 #+BEGIN_SRC emacs-lisp 610 (use-package helm 611 :straight t 612 :commands (helm-find-files helm-buffers-list) 613 :config 614 (bind-key "M-x" 'helm-M-x) 615 (bind-key "C-x C-f" 'helm-find-files) 616 (bind-key "C-c s m" 'helm-man-woman) 617 (bind-key "C-c s a" 'helm-apropos) 618 (bind-key "C-c s i" 'helm-info) 619 (bind-key "C-x i" 'helm-imenu) 620 (bind-key "C-x b" 'helm-buffers-list) 621 (helm-mode 1) 622 (cheatsheet-add-group 'Helm 623 '(:key "C-c s m" :description "Open manual page") 624 '(:key "c-c s a" :description "Emacs apropos") 625 '(:key "C-x i" :description "helm-imenu") 626 '(:key "C-x b" :description "helm-buffers-list"))) 627 (use-package helm-descbinds 628 :straight t 629 :config 630 (bind-key "C-x C-d" 'helm-descbinds) 631 (cheatsheet-add :group "Helm" :key "C-x C-d" :description "helm-descbinds")) 632 (use-package helm-swoop :straight t) 633 #+END_SRC 634 635 ** Academics 636 637 These are the packages that I make/made use of for academic purposes. These are 638 the stuff for notetaking, bibliography management, etc. 639 640 *** Org-mode stuff 641 I am using org-noter and org-roam (which is a zettelkasten) for note-taking, and 642 I find them extremely useful. 643 644 #+BEGIN_SRC emacs-lisp 645 (use-package org-noter 646 :after org 647 :straight t) 648 #+END_SRC 649 650 *** Bibliography stuff 651 I am using helm-bibtex, which is extremely useful navigating bibliography files. 652 #+BEGIN_SRC emacs-lisp 653 (use-package helm-bibtex 654 :straight t) 655 #+END_SRC 656 657 *** PDF Tools 658 PDF Tools come handy when I am working with LaTeX, or when I need to take notes 659 while reading a document. In order to be able to use pdf-tools, you need libpng 660 and poppler (built with private headers). I have a custom =kiss= build for poppler 661 that is as follows. 662 663 #+BEGIN_SRC sh :tangle no 664 #!/bin/sh -e 665 666 export DESTDIR="$1" 667 668 cmake -B build \ 669 -DCMAKE_INSTALL_PREFIX=/usr \ 670 -DCMAKE_INSTALL_LIBDIR=/usr/lib \ 671 -DENABLE_UNSTABLE_API_ABI_HEADERS=ON \ 672 -DENABLE_CPP=ON \ 673 -DENABLE_QT5=OFF \ 674 -DWITH_NSS3=OFF 675 676 cmake --build build 677 cmake --install build 678 #+END_SRC 679 680 #+BEGIN_SRC emacs-lisp 681 (use-package pdf-tools :straight t) 682 #+END_SRC 683 684 ** Extras 685 686 These don't really deserve their own sections, but I prefer to use them. 687 688 *** doas-edit 689 690 This is a package for re-initiating a file as root. 691 692 #+BEGIN_SRC emacs-lisp 693 (use-package doas-edit 694 :straight (:host github :repo "cemkeylan/doas-edit")) 695 #+END_SRC 696 697 *** linum-relative 698 I just like seeing the current line number and the relatives of 699 the other lines. 700 701 #+BEGIN_SRC emacs-lisp 702 (use-package linum-relative 703 :straight t 704 :bind ("C-c r r" . display-line-numbers-mode) 705 :custom 706 (linum-relative-current-symbol "") 707 (display-line-numbers-type 'visual) 708 :hook (prog-mode . display-line-numbers-mode) 709 :config (cheatsheet-add :group "Common" :key "C-c r" :description "toggle line numbers")) 710 #+END_SRC 711 712 *** markdown-mode 713 714 I sometimes use this to test the HTML output of markdown documents 715 that I write. 716 717 #+BEGIN_SRC emacs-lisp 718 (use-package markdown-mode 719 :straight t 720 :config (setq markdown-command "/usr/bin/markdown")) 721 #+END_SRC 722 723 *** htmlize 724 725 I sometimes output html from org-mode as it comes handy. We use htmlize for 726 that. 727 728 #+BEGIN_SRC emacs-lisp 729 (use-package htmlize :straight t) 730 #+END_SRC 731 732 *** toc-org 733 734 I want to have a basic table-of-contents generation on my org-files 735 even without exporting the file itself. This is also useful for the 736 Github README. 737 738 #+BEGIN_SRC emacs-lisp 739 (use-package toc-org 740 :straight t 741 :hook (org-mode . toc-org-mode)) 742 #+END_SRC 743 744 *** which-key 745 746 which-key-mode shows key completions when the user is stuck in a prefix key. 747 748 #+BEGIN_SRC emacs-lisp 749 (use-package which-key 750 :straight t 751 :custom 752 (which-key-popup-type 'side-window) 753 :config 754 (which-key-mode)) 755 #+END_SRC 756 757 *** Treemacs 758 759 #+BEGIN_SRC emacs-lisp 760 (use-package treemacs 761 :straight t 762 :bind ("C-c t" . treemacs)) 763 764 (use-package treemacs-all-the-icons 765 :after (treemacs all-the-icons) 766 :straight t) 767 768 (use-package treemacs-magit 769 :after (treemacs magit) 770 :straight t) 771 772 (use-package treemacs-projectile 773 :after (treemacs projectile) 774 :straight t) 775 776 (use-package treemacs-evil 777 :after (treemacs evil) 778 :straight t) 779 #+END_SRC 780 781 * Filetype Configurations 782 783 I would like to have some different configurations for filetypes. Those are for 784 indents and spaces, mostly. I also like to keep packages specific to stay in 785 their respective categories. 786 787 ** Default Formatting 788 789 Here is the default formatting for most files. I don't like tabs as indents 790 so I avoid them wherever I can. 791 792 #+BEGIN_SRC emacs-lisp 793 (setq-default indent-tabs-mode nil 794 tab-width 8 795 fill-column 80) 796 #+END_SRC 797 798 I am using column number mode to keep track of line status. 799 800 #+BEGIN_SRC emacs-lisp 801 (add-hook 'prog-mode-hook 'column-number-mode) 802 #+END_SRC 803 804 Electric-pair-mode (which is a built-in), matches parentheses on Emacs. While 805 I know that this doesn't form a healthy habit, I really like to have such a 806 function available to me. 807 808 #+BEGIN_SRC emacs-lisp 809 (electric-pair-mode t) 810 #+END_SRC 811 812 813 For some reason, Emacs doesn't deal with trailing whitespace unless you tell it 814 to do so. Let's set it so that Emacs will show trailing whitespace on the buffer 815 and automatically deletes them before save. 816 817 #+BEGIN_SRC emacs-lisp 818 (setq-default show-trailing-whitespace nil) 819 (add-hook 'before-save-hook 'delete-trailing-whitespace) 820 #+END_SRC 821 822 ** Markdown 823 824 For markdown, I want to have 4 spaces as an indentation. 825 826 #+BEGIN_SRC emacs-lisp 827 (use-package markdown-mode 828 :straight t 829 :custom 830 (md-indent-tabs-mode nil) 831 (md-tab-width 4)) 832 #+END_SRC 833 834 ** Shell 835 836 For shell, I want to have 4 spaces as an indentation. 837 838 #+BEGIN_SRC emacs-lisp 839 (use-package sh-script 840 :custom 841 (sh-tab-width 4) 842 (sh-indent-tabs-mode nil)) 843 #+END_SRC 844 845 ** Python 846 I use the django framework quite frequently at work. So I want a few packages 847 for that as well. 848 849 *** Company jedi 850 Company jedi is for better completion while I am editing python files. Here 851 is the use-package 852 853 #+BEGIN_SRC emacs-lisp 854 (use-package company-jedi 855 :straight t 856 :after company 857 :init 858 (add-to-list 'company-backends 'company-jedi)) 859 #+END_SRC 860 861 ** C/C++ 862 863 I am trying to get on with the [[https://www.kernel.org/doc/Documentation/process/coding-style.rst][Kernel Style guide]]. 864 865 #+BEGIN_SRC emacs-lisp 866 (use-package cc-mode 867 :init 868 (defun my-c-hook() 869 "Set indentation size for C." 870 (setq indent-tabs-mode t) 871 (setq c-basic-offset tab-width)) 872 (add-hook 'c-mode-hook 'my-c-hook)) 873 #+END_SRC 874 875 *** Irony-mode 876 I use irony-mode for syntax-checking and completion for C. It can also be used 877 in conjunction with C++, but I personally don't need it. You can add a hook for 878 C++ as well in your [[file:lisp/init-local.el][personal configuration]]. 879 880 #+BEGIN_SRC emacs-lisp :tangle no 881 (add-hook 'c++-mode-hook 'irony-mode) 882 #+END_SRC 883 884 885 This installs =irony=, =company-irony=, and =flycheck-irony=. 886 887 #+BEGIN_SRC emacs-lisp 888 (use-package irony 889 :straight t 890 :hook (c-mode . irony-mode)) 891 892 (use-package flycheck-irony 893 :straight t 894 :after (flycheck irony) 895 :hook (flycheck-mode . flycheck-irony-setup)) 896 897 (use-package company-irony 898 :straight t 899 :after (company irony) 900 :config 901 (add-to-list 'company-backends 'company-irony)) 902 #+END_SRC 903 904 ** Go 905 906 For Go, we are installing =go-mode= and =company-go=. =go-mode= is a rewrite of 907 the built-in major mode for go. =company-go= is the company backend for go. 908 909 #+BEGIN_SRC emacs-lisp 910 (use-package go-mode :straight t) 911 (use-package company-go 912 :straight t 913 :after company 914 ) 915 #+END_SRC 916 917 ** Makefile 918 #+BEGIN_SRC emacs-lisp 919 (use-package helm-make :straight t) 920 #+END_SRC 921 922 ** LaTeX 923 924 I personally use LaTeX for academic papers, but I don't have some advanced 925 configuration on it. 926 927 #+BEGIN_SRC emacs-lisp :tangle no 928 (use-package auctex 929 :straight t) 930 #+END_SRC 931 932 * Themes and Buffer Customization 933 I used to make use of my Xresources themes, but I sometimes sadly 934 need windows, and I actually do want some eye candy from time to 935 time. 936 937 ** Doom themes 938 I want to use the default doom-theme (perhaps I can switch to 939 Dracula someday as well). 940 941 The 'if' statement makes sure we have 942 943 #+BEGIN_SRC emacs-lisp 944 (use-package doom-themes 945 :after all-the-icons 946 :straight t 947 :functions doom-themes-org-config doom-themes-treemacs-config 948 :custom 949 (doom-themes-enable-bold t) 950 (doom-themes-enable-italic t) 951 (doom-themes-treemacs-theme "doom-colors") 952 :config 953 (load-theme 'doom-vibrant t) 954 (doom-themes-treemacs-config) 955 (doom-themes-org-config)) 956 #+END_SRC 957 958 ** All the icons 959 960 All the icons is an icon-pack. I mean it probably isn't hard to 961 guess. Pretty straightforward. 962 963 #+BEGIN_SRC emacs-lisp 964 (use-package all-the-icons 965 :straight t) 966 967 (use-package all-the-icons-dired 968 :straight t 969 :after all-the-icons 970 :hook (dired-mode . all-the-icons-dired-mode)) 971 #+END_SRC 972 973 ** Buffer customisation 974 *** Modeline 975 #+BEGIN_SRC emacs-lisp 976 (use-package doom-modeline 977 :straight t 978 :config (doom-modeline-mode 1)) 979 #+END_SRC 980 981 *** undo-tree 982 983 =undo-tree= provides a nice-looking UI for crawling the buffer history in a 984 visual tree. While this is already a dependency for some packages here, I wanted 985 to specify it anyway. I don't use it frequently, but this is one of the packages 986 that you appreciate having when its time comes. 987 988 #+BEGIN_SRC emacs-lisp 989 (use-package undo-tree 990 :straight t 991 :config 992 (cheatsheet-add :group "Common" :key "C-x u" :description "undo-tree")) 993 #+END_SRC 994 995 *** Highlighting TODO 996 I want to highlight TODO keywords, so I can continue ignoring them in a prettier 997 way. :) 998 999 #+BEGIN_SRC emacs-lisp 1000 (use-package hl-todo 1001 :straight t 1002 :hook (prog-mode . hl-todo-mode)) 1003 #+END_SRC 1004 1005 * Functions 1006 ** Paste Services 1007 Here are two paste-thingies that I use. I got the first code from 1008 [[https://github.com/a-schaefers/dotfiles/blob/2.0/.emacs.d/lisp.d/termbin.el][@a-schaefer's termbin.el]]. 1009 #+BEGIN_SRC emacs-lisp 1010 ;; termbin.el 1011 (defun region-to-termbin (start end) 1012 "Push the marked region (START to END) to termbin.com via shell command." 1013 (interactive "r") 1014 (message "pushing region to termbin.com...") 1015 (shell-command-on-region start end "nc termbin.com 9999")) 1016 1017 (defun buffer-to-termbin () 1018 "Push the buffer to termbin.com via shell command." 1019 (interactive) 1020 (message "pushing buffer to termbin.com...") 1021 (shell-command-on-region (point-min) (point-max) "nc termbin.com 9999")) 1022 1023 ;; pastesrv.el 1024 (defun region-to-srv (start end) 1025 "Push the marked region (START to END) to server via shell command." 1026 (interactive "r") 1027 (message "pushing region to server...") 1028 (shell-command-on-region start end (concat "pastesrv " (read-string "Enter file name (optional): ")))) 1029 1030 (defun buffer-to-srv () 1031 "Push the buffer to server via shell command." 1032 (interactive) 1033 (message "pushing buffer to server...") 1034 (shell-command-on-region (point-min) (point-max) (concat "pastesrv " (read-string "Enter file name (optional): ")))) 1035 1036 (global-set-key (kbd "C-x p r") 'region-to-srv) 1037 (global-set-key (kbd "C-x p b") 'buffer-to-srv) 1038 1039 (cheatsheet-add-group 'Common 1040 '(:key "C-x p r" :description "Push the current region to server") 1041 '(:key "C-x p b" :description "Push the buffer to server")) 1042 #+END_SRC 1043 *** Pastesrv 1044 This is the simple shell script I use to paste to my server. It 1045 is taken from [[https://codemadness.org/paste-service.html][Hiltjo's blog post]]. I use it as a script rather than 1046 a shell function so that I can use it with Emacs. 1047 #+BEGIN_SRC sh :tangle no 1048 #!/bin/sh 1049 1050 # This substitutes a random 4-character string if no file 1051 # name is given. 1052 file="${1:-$(tr -dc "A-Z-a-z-0-9" < /dev/urandom | dd ibs=1 obs=1 count=4 2>/dev/null)}" 1053 1054 # shellcheck disable=2029 1055 ssh user@ckyln.com "cat > /home/www/ckyln.com/files/$file" 1056 printf '%s\n' "https://ckyln.com/files/$file" 1057 #+END_SRC 1058 ** Tangle Init 1059 1060 To load init.el properly we run a function such as this. This 1061 function generates init.el from the source blocks inside this 1062 file using ~org-babel-tangle~ and byte compiles it into ~init.elc~. 1063 After defining the function, we add an ~after-save-hook~ so 1064 that the file is generated everytime we save init.org. 1065 1066 #+BEGIN_SRC emacs-lisp 1067 (defun tangle-init () 1068 "Tangles the init.org file, and byte compiles it." 1069 (when (equal (buffer-file-name) 1070 (expand-file-name (concat user-emacs-directory "init.org"))) 1071 (let ((prog-mode-hook nil)) 1072 (org-babel-tangle) 1073 (byte-compile-file (concat user-emacs-directory "init.el"))))) 1074 1075 (add-hook 'after-save-hook 'tangle-init) 1076 #+END_SRC 1077 1078 * Other Settings 1079 1080 Those are small settings for emacs that I cannot categorize but have importance 1081 for me. 1082 1083 ** xclip 1084 1085 On the terminal, Emacs doesn't have xclip support. I don't like the 1086 inconsistency of switching between terminal and the graphical Emacs. 1087 1088 #+BEGIN_SRC emacs-lisp 1089 (use-package xclip 1090 :if (executable-find "xclip") 1091 :if (getenv "DISPLAY") 1092 :unless (eq system-type 'windows-nt) 1093 :straight t 1094 :config (xclip-mode)) 1095 #+END_SRC 1096 1097 ** shell commands 1098 1099 Typing =M-!= isn't really possible when I am on dwm, so I bind =C-q= for 1100 executing shell commands. I usually prefix shell commands with =C-u= so that I 1101 can easily insert text into buffer. 1102 1103 #+BEGIN_SRC emacs-lisp 1104 (bind-key "C-q" 'shell-command) 1105 #+END_SRC 1106 1107 ** Dired -- ls dired 1108 1109 I use suckless.org's =sbase= as my coreutils. The =ls= program that I use does 1110 not have a =--dired= option. Let's disable it. 1111 1112 #+BEGIN_SRC emacs-lisp 1113 (use-package dired-explorer 1114 :straight t 1115 :custom (dired-use-ls-dired nil)) 1116 #+END_SRC 1117 1118 ** Coding System for Terminal 1119 I want emacs to use utf-8 so my terminal isn't filled with '?' characters. 1120 #+BEGIN_SRC emacs-lisp 1121 (set-terminal-coding-system 'utf-8) 1122 #+END_SRC 1123 1124 ** Backup Options 1125 1126 #+BEGIN_SRC emacs-lisp 1127 (setq backup-directory-alist `(("." . "~/.cache/emacs/saves"))) 1128 #+END_SRC 1129 1130 ** Set Browser 1131 1132 I am setting the default browser from the BROWSER environment variable 1133 so that I don't have to keep track of it in case I ever change my browser. 1134 1135 #+BEGIN_SRC emacs-lisp 1136 (use-package browse-url 1137 :if (getenv "BROWSER") 1138 :custom 1139 (browse-url-generic-program (executable-find (getenv "BROWSER"))) 1140 (browse-url-browser-function 'browse-url-generic)) 1141 #+END_SRC 1142 1143 ** Spelling 1144 1145 As a person who constantly writes documents, spelling is an important part of 1146 the day, huh? 1147 1148 #+BEGIN_SRC emacs-lisp 1149 (use-package flyspell 1150 :if (executable-find "aspell") 1151 :bind (("C-c i r" . flyspell-region) 1152 ("C-c i b" . flyspell-buffer) 1153 ("C-c i m" . flyspell-mode)) 1154 :hook (text-mode . flyspell-mode)) 1155 1156 (use-package ispell 1157 :if (executable-find "aspell") 1158 :bind ("C-c i c" . ispell-change-dictionary) 1159 :custom 1160 (ispell-program-name (executable-find "aspell")) 1161 (ispell-list-command "--list")) 1162 #+END_SRC 1163 1164 ** Local init file 1165 Now that all of this is done, we can load user's personal configuration 1166 1167 #+BEGIN_SRC emacs-lisp 1168 (require 'init-local nil t) 1169 #+END_SRC 1170 1171 ** End of the file 1172 #+BEGIN_SRC emacs-lisp 1173 (provide 'init) 1174 ;;; init.el ends here 1175 #+END_SRC