Skip to content

Latest commit

 

History

History
498 lines (439 loc) · 19 KB

README.org

File metadata and controls

498 lines (439 loc) · 19 KB

My Emacs doom configure

Table of Contents

Configuration

Generate configuration files from this README

Open this file in org-mode and run C-c C-v t

Literate programming with Org-mode

Additional packages

Additional language modes

(package! jinja2-mode)
(package! ahk-mode)
(package! powershell)
(package! nix-mode)
(package! fish-mode)
(package! groovy-mode)
(package! ng2-mode)

Fuzzy file matching

I still prefer ido for file fuzzy matching, doom uses ivy, but I found that with flx, ido is way faster over TRAMP.

(package! flx-ido)

git

List and filter filers in git repository.

(package! helm-ls-git)

Org-mode

;(straight-use-package 'use-package)
;(use-package org-logseq
;  :straight (org-logseq :fetcher github :repo "llcc/org-logseq" :files ("*"))
;  :custom (org-logseq-dir "~/Dropbox/org-mode"))

Bootstrap

Doom modules to use and private module are defined here. Check the same file in emacs doom for new stuff.

(doom! :input
       ;;chinese
       ;;japanese

       :completion
       company           ; the ultimate code completion backend
       ;;helm              ; the *other* search engine for love and life
       ;;ido               ; the other *other* search engine...
       ivy               ; a search engine for love and life

       :ui
       deft              ; notational velocity for Emacs
       doom              ; what makes DOOM look the way it does
       ;doom-dashboard    ; a nifty splash screen for Emacs
       ;doom-quit         ; DOOM quit-message prompts when you quit Emacs
       ;;fill-column       ; a `fill-column' indicator
       hl-todo           ; highlight TODO/FIXME/NOTE tags
       ;;indent-guides     ; highlighted indent columns
       modeline          ; snazzy, Atom-inspired modeline, plus API
       nav-flash         ; blink the current line after jumping
       ;;neotree           ; a project drawer, like NERDTree for vim
       ophints           ; highlight the region an operation acts on
       (popup            ; tame sudden yet inevitable temporary windows
        +all             ; catch all popups that start with an asterix
        +defaults)       ; default popup rules
       ;;pretty-code       ; replace bits of code with pretty symbols
       ;;tabbar            ; FIXME an (incomplete) tab bar for Emacs
       treemacs          ; a project drawer, like neotree but cooler
       ;;unicode           ; extended unicode support for various languages
       vc-gutter         ; vcs diff in the fringe
       vi-tilde-fringe   ; fringe tildes to mark beyond EOB
       window-select     ; visually switch windows
       workspaces        ; tab emulation, persistence & separate workspaces

       :editor
       (evil +everywhere); come to the dark side, we have cookies
       file-templates    ; auto-snippets for empty files
       fold              ; (nigh) universal code folding
       ;;(format +onsave)  ; automated prettiness
       ;;lispy             ; vim for lisp, for people who dont like vim
       multiple-cursors  ; editing in many places at once
       ;;objed             ; text object editing for the innocent
       ;;parinfer          ; turn lisp into python, sort of
       rotate-text       ; cycle region at point between text candidates
       snippets          ; my elves. They type so I don't have to

       :emacs
       (dired            ; making dired pretty [functional]
       ;;+ranger         ; bringing the goodness of ranger to dired
       +icons          ; colorful icons for dired-mode
        )
       electric          ; smarter, keyword-based electric-indent
       vc                ; version-control and Emacs, sitting in a tree
       (undo +tree)

       :term
       ;;eshell            ; a consistent, cross-platform shell (WIP)
       ;;term              ; terminals in Emacs
       ;;vterm             ; another terminals in Emacs

       :checkers
       syntax              ; tasing you for every semicolon you forget
       spell             ; tasing you for misspelling mispelling
       ;;grammar           ; tasing grammar mistake every you make

       :tools
       ;;ansible
       ;;debugger          ; FIXME stepping through code, to help you add bugs
       ;;direnv
       docker
       ;;editorconfig      ; let someone else argue about tabs vs spaces
       ;;ein               ; tame Jupyter notebooks with emacs
       eval              ; run code, run (also, repls)
       ;;gist              ; interacting with github gists
       (lookup           ; helps you navigate your code and documentation
        +docsets)        ; ...or in Dash docsets locally
       (lsp +eglot)
       ;;macos             ; MacOS-specific commands
       magit             ; a git porcelain for Emacs
       ;;make              ; run make tasks from Emacs
       ;;pass              ; password manager for nerds
       ;;pdf               ; pdf enhancements
       ;;prodigy           ; FIXME managing external services & code builders
       ;;rgb               ; creating color strings
       ;;terraform         ; infrastructure as code
       ;;tmux              ; an API for interacting with tmux
       ;;upload            ; map local to remote projects via ssh/ftp
       ;;wakatime

       :lang
       ;;agda              ; types of types of types of types...
       ;;assembly          ; assembly for fun or debugging
       (cc
        +lsp)                                ; C/C++/Obj-C madness
       ;;clojure           ; java with a lisp
       ;;common-lisp       ; if you've seen one lisp, you've seen them all
       ;;coq               ; proofs-as-programs
       ;;crystal           ; ruby at the speed of c
       csharp            ; unity, .NET, and mono shenanigans
       data              ; config/data formats
       ;;erlang            ; an elegant language for a more civilized age
       ;;elixir            ; erlang done right
       ;;elm               ; care for a cup of TEA?
       emacs-lisp        ; drown in parentheses
       ;;ess               ; emacs speaks statistics
       ;;fsharp           ; ML stands for Microsoft's Language
       ;;go                ; the hipster dialect
       ;;(haskell +intero) ; a language that's lazier than I am
       ;;hy                ; readability of scheme w/ speed of python
       ;;idris             ;
       ;;(java +meghanada) ; the poster child for carpal tunnel syndrome
       javascript        ; all(hope(abandon(ye(who(enter(here))))))
       ;;julia             ; a better, faster MATLAB
       kotlin            ; a better, slicker Java(Script)
       latex             ; writing papers in Emacs has never been so fun
       ;;ledger            ; an accounting system in Emacs
       lua               ; one-based indices? one-based indices
       markdown          ; writing docs for people to ignore
       ;;nim               ; python + lisp at the speed of c
       ;;nix               ; I hereby declare "nix geht mehr!"
       ;;ocaml             ; an objective camel
       (org              ; organize your plain life in plain text
       ; +roam2
        +attach          ; custom attachment system
        +babel           ; running code in org
        +capture         ; org-capture in and outside of Emacs
        +export          ; Exporting org to whatever you want
        +habit           ; Keep track of your habits
;        +present         ; Emacs for presentations
        +protocol)       ; Support for org-protocol:// links
       perl              ; write code no one else can comprehend
       ;;php               ; perl's insecure younger brother
       ;;plantuml          ; diagrams for confusing people more
       ;;purescript        ; javascript, but functional
       (python
        +lsp)
       ;;qt                ; the 'cutest' gui framework ever
       ;;racket            ; a DSL for DSLs
       ;;rest              ; Emacs as a REST client
       ;;ruby              ; 1.step {|i| p "Ruby is #{i.even? ? 'love' : 'life'}"}
       ;;rust              ; Fe2O3.unwrap().unwrap().unwrap().unwrap()
       ;;scala             ; java, but good
       sh                ; she sells {ba,z,fi}sh shells on the C xor
       yaml              ; JSON, but readable
       ;;solidity          ; do you need a blockchain? No.
       ;;swift             ; who asked for emoji variables?
       ;;terra             ; Earth and Moon in alignment for performance.
       web               ; the tubes
       ;;vala              ; GObjective-C

       :email
       ;;(mu4e +gmail)       ; WIP
       ;;notmuch             ; WIP
       ;;(wanderlust +gmail) ; WIP

       ;; Applications are complex and opinionated modules that transform Emacs
       ;; toward a specific purpose. They may have additional dependencies and
       ;; should be loaded late.
       :app
       ;;calendar
       ;;irc              ; how neckbeards socialize
       ;;(rss +org)        ; emacs as an RSS reader
       ;;twitter           ; twitter client https://twitter.com/vnought
       ;;(write            ; emacs as a word processor (latex + org + markdown)
       ;; +wordnut         ; wordnet (wn) search
       ;; +langtool)       ; a proofreader (grammar/style check) for Emacs

       :collab
       ;;floobits          ; peer programming for a price
       ;;impatient-mode    ; show off code over HTTP

       :config
       ;; For literate config users. This will tangle+compile a config.org
       ;; literate config in your `doom-private-dir' whenever it changes.
       ;;literate

       ;; The default module sets reasonable defaults for Emacs. It also
       ;; provides a Spacemacs-inspired keybinding scheme and a smartparens
       ;; config. Use it as a reference for your own modules.
       (default +bindings +smartparens)

       :private
       my-python
       my-org
)

Private modules

Python

My python configuration

Python scripts that do not have .py extention name
(add-to-list 'auto-mode-alist '("\\SConscript$" . python-mode))
(add-to-list 'auto-mode-alist '("\\SConstruct$" . python-mode))

Org-mode

Shows child tree item’s progress.

(defun org-summary-todo (n-done n-not-done)
  "Switch entry to DONE when all subentries are done, to TODO otherwise."
  (let (org-log-done org-log-states)   ; turn off logging
    (org-todo (if (= n-not-done 0) "DONE" "TODO"))))

Override doom default configurations.

(after! org
  (setq org-log-into-drawer t)
  (setq org-archive-location "archive.org::* From %s")
  (add-hook 'org-after-todo-statistics-hook 'org-summary-todo)
  (setq org-todo-keywords
   '((sequence "TODO(t)" "STARTED(s!)" "|" "DONE(d!)")
     (sequence "[ ](T)" "[-](P)" "[?](M)" "|" "[X](D!)")
     (sequence "NEXT(n)" "WAIT(w@/!)" "HOLD(h@/!)" "|" "ABRT(c!)"))))

The following is a temp fix, see doomemacs/doomemacs#5706

(defun native-comp-available-p () nil)

Additional custom configuration

Host/machine specific extra config

Load machine sepcific extra config in the beginning as it might be used other configurations.

(setq host-custom-init (concat "~/" system-name ".el"))
(if (file-exists-p host-custom-init)
    (load-file host-custom-init))

Reconfigure doom packages

:completion

Only use ivy fuzzy matching when looking for emacs functions.

(setq ivy-re-builders-alist '((counsel-M-x . ivy--regex-fuzzy)
                              (t . ivy--regex-plus)))

Use ivy with dump jump .

(setq dumb-jump-selector 'ivy)

:editor

Turn off evil mode by default

(after! evil
  (evil-mode 0)
)

:lang

;(after! org
;  (org-roam-buffer-toggle)
;)

:ui

(after! deft
  (setq deft-recursive t)
  ;;don't auto save my notes
  (setq deft-auto-save-interval 0)
  (setq deft-use-filename-as-title t)
  (setq deft-strip-summary-regexp "\\([\n ]\\|^#\\+[[:upper:]_]+:.*$\\|:.*:.*$\\)"))

:tools

On Windows:

  1. Install scoop
  2. scoop install msys2
  3. pacman -Syu aspell aspell-en
(when (boundp 'ispell-program-path)
  (add-to-list 'exec-path ispell-program-path))
(setq ispell-program-name "aspell")

Fly Spell uses middle mouse button to show candidates by default, replace it with right mouse on Mac.

(after! ispell
  (when IS-MAC
    ;; flyspell uses middle mouse button to show candidates by default
    ;; replace it with right mouse on mac
    (eval-after-load "flyspell" '(progn (define-key flyspell-mouse-map [down-mouse-3]
                                          #'flyspell-correct-word)
                                        (define-key flyspell-mouse-map [mouse-3] #'undefined)))))

Font and UI

Title format : buffer name @ hostname

(setq frame-title-format (concat "%b@emacs." (system-name)))

OS dependent font configuration

(when (display-graphic-p)
  ;;run M-x all-the-icons-install-fonts to use icons theme
  ;;(setq neo-theme 'icons)
  (if IS-WINDOWS
      (setq my-font "Consolas-10")
    (if IS-MAC
        (setq my-font "SF Mono-12")
      (setq my-font "Droid Sans Mono Slashed for Powerline-10")))
  (set-frame-font my-font)
  (set-face-attribute 'default t
                      :font my-font)
  (if IS-WINDOWS (set-fontset-font "fontset-default" 'gb18030 '("Microsoft YaHei" .
                                                                "unicode-bmp"))))
;(setq doom-theme 'doom-dracula)

Others

Override find-file

(require 'flx-ido) ; fuzzy match
(ido-mode 'file)  ; use 'buffer rather than t to use only buffer switching
(flx-ido-mode 1)
;; disable ido faces to see flx highlights.
(setq ido-enable-flex-matching t)
(setq ido-use-faces nil)
(setq ido-use-filename-at-point nil)
(setq ido-auto-merge-work-directories-length 0)
(setq ido-use-virtual-buffers t)
;; @see https://github.com/lewang/flx
(setq flx-ido-threshold 10000)
;; Allow the same buffer to be open in different frames
(setq ido-default-buffer-method 'selected-window)

;; disable ido for certain commands,
;; @see http://stackoverflow.com/questions/6771664/disable-ido-mode-for-specific-commands
(defadvice ido-read-buffer (around ido-read-buffer-possibly-ignore activate)
  "Check to see if use wanted to avoid using ido"
  (if (eq (get this-command 'ido) 'ignore)
      (let ((read-buffer-function nil))
        (run-hook-with-args 'ido-before-fallback-functions 'read-buffer)
        (setq ad-return-value (apply 'read-buffer (ad-get-args 0))))
    ad-do-it))
(put 'shell 'ido 'ignore)
(put 'ffap-alternate-file 'ido 'ignore)
(put 'tmm-menubar 'ido 'ignore)
(put 'dired-do-copy 'ido 'ignore)
(put 'dired-do-rename 'ido 'ignore)
(put 'vc-copy-file-and-rename-buffer 'ido 'ignore)
(put 'dired-create-directory 'ido 'ignore)
(put 'copy-file-and-rename-buffer 'ido 'ignore)
(put 'rename-file-and-buffer 'ido 'ignore)
(put 'w3m-goto-url 'ido 'ignore)
(put 'ido-find-file 'ido 'ignore)
(put 'ido-edit-input 'ido 'ignore)
(put 'read-file-name 'ido 'ignore)
(put 'dired-create-directory 'ido 'ignore)
(put 'minibuffer-completion-help 'ido 'ignore)
(put 'minibuffer-complete 'ido 'ignore)
(put 'c-set-offset 'ido 'ignore)
(put 'rgrep 'ido 'ignore)
(put 'dired-create-directory 'ido 'ignore)

Tramp

(add-to-list 'backup-directory-alist (cons tramp-file-name-regexp nil))
(setq tramp-chunksize 8192)
;; @see https://github.com/syl20bnr/spacemacs/issues/1921
;; If you tramp is hanging, you can uncomment below line.
;; (setq tramp-ssh-controlmaster-options "-o ControlMaster=auto -o ControlPath='tramp.%%C' -o ControlPersist=no")

Org Roam

;(org-roam-db-autosync-mode)
(setq org-roam-dailies-directory "journals/")
(setq org-roam-dailies-capture-templates
      '(("d" "default" entry
         "* %?"
         :target (file+head "%<%Y_%m_%d>.org"
                            "#+title: %<%Y-%m-%d>\n"))))
(setq org-startup-with-inline-images t)

Override Emacs defaults

(put 'narrow-to-region 'disabled nil)

Start Emacs Server

(server-start)

Key bindings

(global-set-key (kbd "C-x g") 'magit-status)

;; https://github.com/emacs-helm/helm-ls-git
(global-set-key (kbd "M-p") 'helm-ls-git-ls)

(global-set-key [(control -)] 'set-mark-command)

(global-set-key [f2] 'deft)
(global-set-key [f4] 'ibuffer)
(global-set-key [f5] 'neotree-toggle)
(global-set-key (kbd "C-S-g") 'goto-line)

(when IS-MAC (global-unset-key [home])
      (global-set-key [home] 'move-beginning-of-line)
      (global-unset-key [end])
      (global-set-key [end] 'move-end-of-line))

Others

Create Windows config dump

7z a -xr'!.git' emacs.doom.7z .doom.d .emacs.d