Files
dotfiles/doom.d/config.org
2019-10-13 23:19:47 +01:00

12 KiB

Oreodave's emacs configuration

Preclude

This is my Doom Emacs configuration, which I try to use for as many things as possibe. It is currently my main C# and Python editor but hopefully it will become my C one soon!

Notes and keybinds

Bind Use Context
<C-c '> To edit a src block Org
<C-c C-o> To read the buffer results into a traversible buffer, so you can read it and do normal vim stuff with it Counsel
<C-c C-p> To edit results buffer. You can edit specific items or the entire thing using a regex. Incredibly useful Counsel results
<C-o> When you've gone to some line or definiton, go back to previous place Normal
<C-x h> Mark whole buffer for copying Normal

Global variables

(setq doom-localleader-key ",")
(setq warning-minimum-level :emergency)
(setq completion-ignore-case t)
(setq org-directory "~/Text")
(setq truncate-lines t)
  • '<SPC>m' is right next to ',', so may as well use one tap instead of two
  • Projectile tags commands

General keymap

(map!
 :leader
 :desc   "M-x"                "<SPC>" 'counsel-M-x
 :desc   "Switch to p-buffer" ">"     'projectile-switch-to-buffer
 :desc   "Indent"             "j"     'indent-region
 :desc   "Reload emacs"       "r"     'oreodave/reload
 :desc   "Compile via make"   "cC"    '+make/run
                                        ; Redefine <SPC><SPC> as M-x rather than find-file because of my muscle memory with spacemacs
                                        ; General maps like <SPC>j for indenting because I don't know what else to bind them to
                                        ; <SPC>pf => project -> find file
 (:prefix "/" ; Search
   :after counsel
   :desc "Ag!"                "a"     '+ivy/ag
   :desc "FZF!"               "f"     'counsel-fzf
   :desc "RipGrep!"           "r"     'counsel-rg
   :desc "Search Tags"        "t"     'counsel-etags-find-tag
   :desc "List Tags"          "T"     'counsel-etags-list-tag
   :desc "Buffer Tags"        "s"     'counsel-imenu
   :desc "Search buffer"      "/"     'swiper
   )
                                        ; I like using <SPC>/ in comparison to <SPC>s: it's closer together (thus quicker, I do searches a lot so this is noticeable) and makes more sense
                                        ; Ripgrep is faster than Ag in most cases and makes me feel cool
                                        ; <SPC>// is quicker to do than <SPC>/b, for something that is done so often

 (:prefix "w" ; Windows
   :desc "Close window"       "d"     '+workspace/close-window-or-workspace
   :desc "Switch window"      "W"     'ace-window
   :desc "Swap windows"       "S"     'ace-swap-window
   )
                                        ; <SPC>wd is slightly closer together than <SPC>wc
                                        ; <SPC>wd is also used in spacemacs so I'd rather use this
                                        ; <SPC>wW allows me to switch windows more efficiently than before, better than just motions

 (:prefix "b"
   :desc "Close buffer"       "d"     'doom/kill-this-buffer-in-all-windows
   )
                                        ; <SPC>bd is used for the same reasons as above

 (:prefix "p"
   :after projectile
   :desc "Regen tags"         "g"     'projectile-regenerate-tags
   :desc "Open project files" "f"     'projectile-find-file
   )
 )
; <SPC>pg for regenning tags is useful when searching them

Custom

Packages

Projectile

(after! projectile
  (setq oreodave-tags-alist '("Makefile" "node_modules" "bin" "dist" "obj" "'*.json'"))
  (defun oreodave/config/construct-tags ()
    (reduce (lambda (x y) (concat x y)) (mapcar (lambda (i) (concat " --exclude=" i)) oreodave-tags-alist)
            :initial-value "exctags -Re ")
    )
  (setq projectile-tags-command (oreodave/config/construct-tags))
  )

Really simple, just want to set projectile-tags-command when projectile has loaded

Wakatime

(setq wakatime-api-key (shell-command-to-string "pass Keys/Wakatime"))

Using new password holder (pass) to help with secure transactions.

Elfeed

(after! elfeed
  (defun oreodave/elfeed/load-feeds ()
    (interactive)
    (setq elfeed-feeds nil)
    (elfeed-load-opml (concat org-directory "/elfeed.opml")))

  (defun oreodave/elfeed/on-new-feed ()
    (interactive)
    (elfeed-org-export-opml)
    (write-file (concat org-directory "/elfeed.opml"))
    (kill-current-buffer)
    )

  (map!
   :map elfeed-search-mode-map
   :localleader
   :desc "Update feeds" "u" 'elfeed-update
   )

  (add-hook 'elfeed-org-new-entry-hook 'oreodave/elfeed/on-new-feed)
  ;; (oreodave/elfeed/load-feeds)
  )

Dash

(setq dash-docs-docsets-path "~/.docsets")

My docsets are stored in .docsets for ease of use

wttrin

(after! wttrin
  (defun oreodave/weather ()
    (interactive)
    (wttrin (shell-command-to-string "pass location"))))

Custom functionality

Code

(map!
 :leader
 :prefix "c"
 :desc "Fold all in level"  "f" 'hs-hide-level
 )

Books

(map!
 :leader
 :desc "Open folder" "B" '(lambda () (interactive) (dired "~/Text/Books"))
 )

Download Items

(defun oreodave/request-json-fn (url)
  (set-process-sentinel
   (start-process-shell-command "request-json" "*request-json*" (format "curl %s" url))
   (lambda (process event)
     (when (memq (process-status process) '(exit stop))
       (message "Request finished")
       (with-current-buffer "*request-json*"
         (json-mode)
         (json-mode-beautify))))))

(defun oreodave/request-json ()
  (interactive)
  (oreodave/request-json-fn (read-string "Enter url: "))
  )

Themes

(setq oreodave/aesthetics/list '(doom-molokai doom-peacock doom-solarized-dark))
(setq oreodave/aesthetics/index 2)
(load-theme (nth oreodave/aesthetics/index oreodave/aesthetics/list))

(defun oreodave/aesthetics/next-theme ()
  (interactive)
  (cond ((= 2 oreodave/aesthetics/index) (setq oreodave/aesthetics/index 0))
        (t (setq oreodave/aesthetics/index (+ oreodave/aesthetics/index 1))))
  (load-theme (nth oreodave/aesthetics/index oreodave/aesthetics/list)))

(map!
 :leader
 :prefix ("a" . "+aesthetics")
 :desc "Load themes"        "a" 'load-theme
 :desc "Next default theme" "n" 'oreodave/aesthetics/next-theme
 )
  • I want to have similar functionality to spacemacs: a way to switch themes easily and quickly

Frame management

(map!
 :leader
 ; TODO think of a new prefix or leave and justfiy this one
 :prefix ("m" . "Frame") ; Literally the first free prefix I could think of
 :desc "Kill frame"                  "d" 'delete-frame
 :desc "Make current buffer frame"   "m" 'make-frame
 :desc "Choose buffer to make frame" "n" 'display-buffer-other-frame
 :desc "Switch frames"               "o" 'other-frame
 )
  • This is my config for handling new frames
  • I've only recently found out about them, they're incredibly powerful tools that I should've put in my toolbox a LONG time ago

Font size

(map!
 :leader
 :prefix ("z" . "Font") ; using this prefix due to spacemacs
 :desc "Increase font"  "+" 'doom/increase-font-size
 :desc "Decreease font" "-" 'doom/decrease-font-size
 :desc "Adjust font"    "z" 'text-scale-adjust
 )

Custom functions

(defun oreodave/reload ()
  (interactive)
  (load-file (concat doom-private-dir "config.el"))
  )

Languages

C#

(after! csharp-mode
  (defun oreodave/csharp/get-unit-test-in-project ()
    (interactive)
    (let* ((tags-file (counsel-etags-locate-tags-file))
           (cands (counsel-etags-collect-cands "void.*Test" t buffer-file-name)))
      (ivy-read "Choose test: "
                cands
                :action
                (lambda (item)
                  ;; From the counsel-etags file-open-api function
                  (when (string-match "\\`\\(.*?\\):\\([0-9]+\\):\\(.*\\)\\'" item)
                    (let* ((file (match-string-no-properties 1 item))
                           (linenum (match-string-no-properties 2 item))
                           ;; always calculate path relative to TAGS
                           (default-directory (counsel-etags-tags-file-directory)))

                      (when counsel-etags-debug
                        (message "counsel-etags-open-file-api called => dir=%s, linenum=%s, file=%s" dir linenum file))

                      (counsel-etags-push-marker-stack (point-marker))
                      (find-file file)
                      (counsel-etags-forward-line linenum)
                      (omnisharp-unit-test-at-point)
                      )))
                :caller 'oreodave/csharp/get-unit-tests-in-project)))

  (setq omnisharp-server-executable-path "~/bin/omnisharp/run")
  (add-hook 'csharp-mode-hook '(lambda()
                                 (setq c-basic-offset 4)
                                 (setq c-default-style "stroustrup"))) ; Hook for csharp setting variables

  (map! ; CSharp Keybinds
   :map csharp-mode-map
   :localleader
   :desc   "Format buffer"            "="   'omnisharp-code-format-entire-file
   (:prefix "t"
     :desc "Select Test in Project"    "t"   'oreodave/csharp/get-unit-test-in-project
     )))
  • I have custom installed the omnisharp roslyn executable, so I'd rather use that
  • C# code is better at 4 space indents, but I indent most of my C code at 2 space indents because it looks nicer :)
  • Reimplemented omnisharp emit messages for stdout
  • Implemented my own function which piggy backs counsel etags to globally search tags for test specific context, then goes to it and uses an omnisharp test command to unit test it

Python

(after! python
  (setq python-version-checked t)
  (setq python-python-command "python3")
  (setq python-shell-interpreter "python3")
  (setq flycheck-python-pycompile-executable "python3")

  (map! ; Python keybinds
   :map python-mode-map
   :localleader
   :desc "Start python minor" "c" 'run-python
   :desc "Format buffer"      "=" 'py-yapf-buffer
   (:prefix "s"
     :desc "Send region REPL" "r" 'python-shell-send-region
     :desc "Send buffer"      "b" 'python-shell-send-buffer
     :desc "Send function"    "f" 'python-shell-send-defun
     )
   )
  )
  • I do python development for Python3 (who doesn't?), so I need to set the flycheck python checker, as well as the interpreter, to be Python3
  • Python keybinds
  • Most of my python work is in scripts or ideas, so I don't need extensive testing utilities or anything like that
  • I run my python code a LOT and thus need commands for sending bits or whole scripts into the REPL

JavaScript/TypeScript

(after! typescript-mode
  (setq typescript-indent-level 2)
  (setq tide-format-options '(:indentSize 2 :tabSize 2))
  (map!
   :localleader
   :map typescript-mode-map
   :desc "Format code" "=" 'tide-format
   )
  )
  • Typescript (in my opinion) should be indented by 2
  • I like having one keybind to format a file, thus need to rebind

Org

(after! org
  (add-hook 'org-mode-hook #'visual-line-mode)
  (remove-hook 'org-mode-hook #'auto-fill-mode)
  (map! ; Org keybinds
   :map org-mode-map
   (:localleader
     :desc "Org dispatch"      "ee" #'org-export-dispatch
     :desc "Export to ODT"     "E"  #'org-pandoc-export-to-odt)
  ))

I like using the org dispatch facilities more than the default export keybinds in Doom, so I need this binding