GuangTao’s Doom Emacs config

Table of Contents

HTML them READ org

1 Emacs

Emacs or EMACS (Editor MACroS) is a family of text editors that are characterized by their extensibility. The manual for the most widely used variant, GNU Emacs, describes it as “the extensible, customizable, self-documenting, real-time display editor”. Development of the first Emacs began in the mid-1970s, and work on its direct descendant, GNU Emacs, continues actively as of 2020.

2 init.el

;;; init.el -*- lexical-binding: t; -*-

;; Copy this file to ~/.doom.d/init.el or ~/.config/doom/init.el ('doom install'
;; will do this for you). The `doom!' block below controls what modules are
;; enabled and in what order they will be loaded. Remember to run 'doom refresh'
;; after modifying it.
;;
;; More information about these modules (and what flags they support) can be
;; found in modules/README.org.

(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/DEPRECATED/HACK/REVIEW
       ;;hydra
       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 +defaults)   ; tame sudden yet inevitable temporary windows
       ;;pretty-code       ; replace bits of code with pretty symbols
       ;;tabs              ; an 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
       ;;god               ; run Emacs commands without modifier keys
       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
       ;;word-wrap         ; soft wrapping with language-aware indent

       :emacs
       dired             ; making dired pretty [functional]
       electric          ; smarter, keyword-based electric-indent
       ibuffer           ; interactive buffer management
       vc                ; version-control and Emacs, sitting in a tree

       :term
       ;;eshell            ; a consistent, cross-platform shell (WIP)
       ;;shell             ; a terminal REPL for Emacs
       ;;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 +overlay)     ; run code, run (also, repls)
       ;;flycheck          ; tasing you for every semicolon you forget
       ;;flyspell          ; tasing you for misspelling mispelling
       ;;gist              ; interacting with github gists
       (lookup           ; helps you navigate your code and documentation
        +docsets)        ; ...or in Dash docsets locally
       lsp
       ;;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

       :os
       (:if IS-MAC macos)  ; improve compatibility with macOS

       :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
       ;;faust             ; dsp, but you get to keep your soul
       ;;fsharp           ; ML stands for Microsoft's Language
       go                ; the hipster dialect
       json

       haskell ; 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
       ;;lean
       ;;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
        +dragndrop       ; drag & drop files/images into org buffers
        +hugo            ; use Emacs for hugo blogging
        +ipython         ; ipython/jupyter support for babel
        +pandoc          ; export-with-pandoc support
        +roam
        ;;+helm-org
        ;+pomodoro        ; be fruitful with the tomato technique
        +present)        ; using org-mode for presentations
       ;;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
        +poetry
        +lsp
        +pyright)            ; beautiful is better than ugly
       ;;qt                ; the 'cutest' gui framework ever
       ;;racket            ; a DSL for DSL
       ;;ruby              ; 1.step {|i| p "Ruby is #{i.even? ? 'love' : 'life'}"}
       rust              ; Fe2O3.unwrap().unwrap().unwrap().unwrap()
       ;;scala             ; java, but good
       ;;scheme            ; a fully conniving family of lisps
       sh                ; she sells {ba,z,fi}sh shells on the C xor
       ;;solidity          ; do you need a blockchain? No.
       ;;swift             ; who asked for emoji variables?
       ;;terra             ; Earth and Moon in alignment for performance.
       ;;web               ; the tubes

       :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 for writers (fiction, notes, papers, etc.)
       ;; +wordnut         ; wordnet (wn) search
       ;; +langtool)       ; a proofreader (grammar/style check) for Emacs

       :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 +smartparens)
         :private
         spacemacs-default
         my-org
         my-code
         )

3 package.el

;;; packages.el -*- lexical-binding: t; -*-
(package! discover :recipe (:host github :repo "mickeynp/discover.el"))
(package! xah-fly-keys :recipe (:host github :repo "xahlee/xah-fly-keys"))
(package! maple-iedit :recipe (:host github :repo "honmaple/emacs-maple-iedit"))
(package! ctrlf :recipe (:host github :repo "raxod502/ctrlf"))
(package! scrollkeeper :recipe (:host github :repo "alphapapa/scrollkeeper.el"))
(package! awesome-tab :recipe (:host github :repo "manateelazycat/awesome-tab"))
(package! ob-session-async :recipe (:host github :repo "jackkamm/ob-session-async"))
(package! maple-explorer :recipe (:host github :repo "honmaple/emacs-maple-explorer"))
(package! sunrise-commander :recipe (:host github :repo "sunrise-commander/sunrise-commander"))
(package! awesome-pair :recipe (:host github :repo "manateelazycat/awesome-pair"))

(unpin! magit)
;; (package! berrys-theme)

4 config.el

;;; config.el -*- lexical-binding: t; -*-

(load! "xah-fly-keys.el")
(load! "show-parentheses.el")
  • native compile
;;(setq comp-async-jobs-number 24)

5 use-package

5.1 helm-tramp

(package! helm-tramp)
(use-package! helm-tramp
  :config
  (setq tramp-default-method "sshx")
  (setq make-backup-files nil)
  (setq create-lockfiles nil)
  (setq helm-tramp-custom-connections '(/sshx:gtrun@10.220.170.112:/home/gtrun
                                        /sshx:gtrun@10.220.170.112:/home/gtrun/.config/nixpkgs
                                        /sshx:test@10.220.170.113:/home/test/))
  (add-hook 'helm-tramp-pre-command-hook '(lambda () ;;(global-aggressive-indent-mode 0)
                     (projectile-mode 0)
                     ;;(editorconfig-mode 0)
             ))
  (add-hook 'helm-tramp-quit-hook '(lambda () ;;(global-aggressive-indent-mode 1)
                  (projectile-mode 1)
                  ;;(editorconfig-mode 1)
            ))
)

5.2 Pinyin

(package! pinyin-search)
(use-package! pinyin-search)

5.3 wakatime-mode

(package! wakatime-mode)
(use-package! wakatime-mode
:hook (after-init . global-wakatime-mode))

5.4 ctrlf

;; (use-package! ctrlf
;;   :config
;;   (add-hook! 'after-init-hook #'ctrlf-mode)
;; )

5.5 vlf

(package! vlf)
(use-package! vlf
  :config
  (require 'vlf-setup)
  (custom-set-variables
   '(vlf-application 'dont-ask))
)

5.6 maple-explorer

(use-package! maple-explorer
  :commands (maple-explorer-file maple-explorer-buffer maple-explorer-imenu maple-explorer-recentf)
  :config
  (setq maple-explorer-file-display-alist '((side . left) (slot . -1)))
  (add-hook 'maple-explorer-imenu-mode-hook
            (lambda() (setq cursor-type 'box
                            cursor-in-non-selected-windows t)))
)

5.7 imenu-list

(package! imenu-list)
(use-package! imenu-list
  :config
  (setq imenu-list-auto-resize t)
  (setq imenu-list-focus-after-activation t)
  (setq imenu-list-after-jump-hook nil)
  (add-hook 'menu-list-after-jump-hook #'recenter-top-bottom)
)

5.8 w3m

(package! w3m)
(use-package! w3m
  :commands (w3m)
  :config
  (setq w3m-use-tab-line nil)
)

5.9 ein

(package! ein :recipe (:host github
                       :repo "millejoh/emacs-ipython-notebook"
                       :files ("lisp/*.el")
                       :no-byte-compile t))
(use-package! ein
  :config
  (setq ob-ein-languages
   (quote
    (("ein-python" . python)
     ("ein-R" . R)
     ("ein-r" . R)
     ("ein-rust" . rust)
     ("ein-haskell" . haskell)
     ("ein-julia" . julia))))
  )

(after! ein:ipynb-mode                  ;
  (poly-ein-mode 1)
  (hungry-delete-mode -1)
  )

5.10 undo

(package! undo-fu)
(package! undo-fu-session)
(use-package! undo-fu
  :after-call doom-switch-buffer after-find-file
  :init
  (after! undo-tree
    (global-undo-tree-mode -1))
  :config
  ;; Store more undo history to prevent loss of data
  (setq undo-limit 400000
        undo-strong-limit 3000000
        undo-outer-limit 3000000)

  (define-minor-mode undo-fu-mode
    "Enables `undo-fu' for the current session."
    :keymap (let ((map (make-sparse-keymap)))
              (define-key map [remap undo] #'undo-fu-only-undo)
              (define-key map [remap redo] #'undo-fu-only-redo)
              (define-key map (kbd "C-_")     #'undo-fu-only-undo)
              (define-key map (kbd "M-_")     #'undo-fu-only-redo)
              (define-key map (kbd "C-M-_")   #'undo-fu-only-redo-all)
              (define-key map (kbd "C-x r u") #'undo-fu-session-save)
              (define-key map (kbd "C-x r U") #'undo-fu-session-recover)
              map)
    :init-value nil
    :global t)

  (undo-fu-mode +1))

(use-package! undo-fu-session
  :hook (undo-fu-mode . global-undo-fu-session-mode)
  :preface
  (setq undo-fu-session-directory (concat doom-cache-dir "undo-fu-session/")
        undo-fu-session-incompatible-files '("/COMMIT_EDITMSG\\'" "/git-rebase-todo\\'"))

  ;; HACK We avoid `:config' here because `use-package's `:after' complicates
  ;;      the load order of a package's `:config' block and makes it impossible
  ;;      for the user to override its settings with merely `after!' (or
  ;;      `eval-after-load'). See jwiegley/use-package#829.
  (after! undo-fu-session
    ;; HACK Use the faster zstd to compress undo files instead of gzip
    (when (executable-find "zstd")
      (defadvice! doom--undo-fu-session-use-zstd-a (filename)
        :filter-return #'undo-fu-session--make-file-name
        (if undo-fu-session-compression
            (concat (file-name-sans-extension filename) ".zst")
          filename)))))

(use-package! undo-tree
  :disabled
  ;; Branching & persistent undo
  :after-call doom-switch-buffer-hook after-find-file
  :config
  (setq undo-tree-visualizer-diff t
        undo-tree-auto-save-history t
        undo-tree-enable-undo-in-region t
        ;; Increase undo-limits by a factor of ten to avoid emacs prematurely
        ;; truncating the undo history and corrupting the tree. See
        ;; https://github.com/syl20bnr/spacemacs/issues/12110
        undo-limit 800000
        undo-strong-limit 12000000
        undo-outer-limit 120000000
        undo-tree-history-directory-alist
        `(("." . ,(concat doom-cache-dir "undo-tree-hist/"))))

  ;; Compress undo-tree history files with zstd, if available. File size isn't
  ;; the (only) concern here: the file IO barrier is slow for Emacs to cross;
  ;; reading a tiny file and piping it in-memory through zstd is *slightly*
  ;; faster than Emacs reading the entire undo-tree file from the get go (on
  ;; SSDs). Whether or not that's true in practice, we still enjoy zstd's ~80%
  ;; file savings (these files add up over time and zstd is so incredibly fast).
  (when (executable-find "zstd")
    (defadvice! doom--undo-tree-make-history-save-file-name-a (file)
      :filter-return #'undo-tree-make-history-save-file-name
      (concat file ".zst")))

  ;; Strip text properties from undo-tree data to stave off bloat. File size
  ;; isn't the concern here; undo cache files bloat easily, which can cause
  ;; freezing, crashes, GC-induced stuttering or delays when opening files.
  (defadvice! doom--undo-tree-strip-text-properties-a (&rest _)
    :before #'undo-list-transfer-to-tree
    (dolist (item buffer-undo-list)
      (and (consp item)
           (stringp (car item))
           (setcar item (substring-no-properties (car item))))))

  ;; Undo-tree is too chatty about saving its history files. This doesn't
  ;; totally suppress it logging to *Messages*, it only stops it from appearing
  ;; in the echo-area.
  (advice-add #'undo-tree-save-history :around #'doom-shut-up-a)

  (global-undo-tree-mode +1))

5.11 color-rg

(package! color-rg :recipe (:host github :repo "manateelazycat/color-rg"))
(use-package! color-rg
  :commands (color-rg-search-input color-rg-search-symbol
                                   color-rg-search-input-in-project
                                   )
  :bind
  (:map isearch-mode-map
   ("M-s M-s" . isearch-toggle-color-rg))
  )

5.12 envrc

(package! envrc :recipe (:host github :repo "purcell/envrc"))
(use-package! envrc
:hook (after-init . envrc-global-mode)
)

5.13 snails

  (package! snails :recipe (:host github
                            :repo "manateelazycat/snails"
                            :files ("*.el")
                            :no-byte-compile t))
(use-package! snails
  :config
  (define-key snails-mode-map [remap next-line] #'snails-select-next-item))

5.14 good-scroll.el

  (package! good-scroll :recipe (:host github
                                 :repo "io12/good-scroll.el"))
(use-package! good-scroll
  :config
  (good-scroll-mode 1)
)

5.15 helm-tramp

5.16 helm-rg

  • [2021-01-08 Fri 17:49] <- org-z
(package! helm-rg)
(use-package! helm-rg)

6 autoload

6.1 +misc.el

6.1.1 timer

;;; ~/.doom.d/autoload/misc.el -*- lexical-binding: t; -*-
(defvar current-date-time-format "%a %b %d %H:%M:%S %Z %Y"

  "Format of date to insert with `insert-current-date-time' func
See help of `format-time-string' for possible replacements")

;;;###autoload
(defun insert-current-date-time ()
  "insert the current date and time into current buffer.
Uses `current-date-time-format' for the formatting the date/time."
       (interactive)
       ;;(insert "==========\n")
;       (insert (let () (comment-start)))
       (insert (format-time-string current-date-time-format (current-time)))
       )

(defvar current-date-time-format-inactive "[%Y-%m-%d %a %H:%M]"

  "Format of date to insert with `insert-current-date-time' func
See help of `format-time-string' for possible replacements")

;;;###autoload
(defun insert-current-date-time-inactive
 ()
  "insert the current date and time into current buffer.
Uses `current-date-time-format' for the formatting the date/time."
       (interactive)
       ;;(insert "==========\n")
;       (insert (let () (comment-start)))
       (insert (format-time-string current-date-time-format-inactive (current-time)))
       ;;(insert "\n")
       )

(defvar current-date-time-format-active "<%Y-%m-%d %a %H:%M>"

  "Format of date to insert with `insert-current-date-time' func
See help of `format-time-string' for possible replacements")

;;;###autoload
(defun insert-current-date-time-active
 ()
  "insert the current date and time into current buffer.
Uses `current-date-time-format' for the formatting the date/time."
       (interactive)
       ;;(insert "==========\n")
;       (insert (let () (comment-start)))
       (insert (format-time-string current-date-time-format-active (current-time)))
       ;;(insert "\n")
       )

6.2 +org-mode.el

6.2.1 alphapapa/unpackaged.el: A collection of useful Emacs Lisp code that isn’t substantial enough to be packaged

;;; ~/.doom.d/autoload/+org-mode.el -*- lexical-binding: t; -*-
(defun unpackaged/org-element-descendant-of (type element)
  "Return non-nil if ELEMENT is a descendant of TYPE.
TYPE should be an element type, like `item' or `paragraph'.
ELEMENT should be a list like that returned by `org-element-context'."
  ;; MAYBE: Use `org-element-lineage'.
  (when-let* ((parent (org-element-property :parent element)))
    (or (eq type (car parent))
        (unpackaged/org-element-descendant-of type parent))))

;;;###autoload
(defun unpackaged/org-fix-blank-lines (&optional prefix)
  "Ensure that blank lines exist between headings and between headings and their contents.
With prefix, operate on whole buffer. Ensures that blank lines
exist after each headings's drawers."
  (interactive "P")
  (org-map-entries (lambda ()
                     (org-with-wide-buffer
                      ;; `org-map-entries' narrows the buffer, which prevents us from seeing
                      ;; newlines before the current heading, so we do this part widened.
                      (while (not (looking-back "\n\n" nil))
                        ;; Insert blank lines before heading.
                        (insert "\n")))
                     (let ((end (org-entry-end-position)))
                       ;; Insert blank lines before entry content
                       (forward-line)
                       (while (and (org-at-planning-p)
                                   (< (point) (point-max)))
                         ;; Skip planning lines
                         (forward-line))
                       (while (re-search-forward org-drawer-regexp end t)
                         ;; Skip drawers. You might think that `org-at-drawer-p' would suffice, but
                         ;; for some reason it doesn't work correctly when operating on hidden text.
                         ;; This works, taken from `org-agenda-get-some-entry-text'.
                         (re-search-forward "^[ \t]*:END:.*\n?" end t)
                         (goto-char (match-end 0)))
                       (unless (or (= (point) (point-max))
                                   (org-at-heading-p)
                                   (looking-at-p "\n"))
                         (insert "\n"))))
                   t (if prefix
                         nil
                       'tree)))


;;;###autoload
(defun unpackaged/org-return-dwim (&optional default)
  "A helpful replacement for `org-return'.  With prefix, call `org-return'.

On headings, move point to position after entry content.  In
lists, insert a new item or end the list, with checkbox if
appropriate.  In tables, insert a new row or end the table."
  ;; Inspired by John Kitchin: http://kitchingroup.cheme.cmu.edu/blog/2017/04/09/A-better-return-in-org-mode/
  (interactive "P")
  (if default
      (org-return)
    (cond
     ;; Act depending on context around point.

     ;; NOTE: I prefer RET to not follow links, but by uncommenting this block, links will be
     ;; followed.

     ;; ((eq 'link (car (org-element-context)))
     ;;  ;; Link: Open it.
     ;;  (org-open-at-point-global))

     ((org-at-heading-p)
      ;; Heading: Move to position after entry content.
      ;; NOTE: This is probably the most interesting feature of this function.
      (let ((heading-start (org-entry-beginning-position)))
        (goto-char (org-entry-end-position))
        (cond ((and (org-at-heading-p)
                    (= heading-start (org-entry-beginning-position)))
               ;; Entry ends on its heading; add newline after
               (end-of-line)
               (insert "\n\n"))
              (t
               ;; Entry ends after its heading; back up
               (forward-line -1)
               (end-of-line)
               (when (org-at-heading-p)
                 ;; At the same heading
                 (forward-line)
                 (insert "\n")
                 (forward-line -1))
               ;; FIXME: looking-back is supposed to be called with more arguments.
               (while (not (looking-back (rx (repeat 3 (seq (optional blank) "\n")))))
                 (insert "\n"))
               (forward-line -1)))))

     ((org-at-item-checkbox-p)
      ;; Checkbox: Insert new item with checkbox.
      (org-insert-todo-heading nil))

     ((org-in-item-p)
      ;; Plain list.  Yes, this gets a little complicated...
      (let ((context (org-element-context)))
        (if (or (eq 'plain-list (car context))  ; First item in list
                (and (eq 'item (car context))
                     (not (eq (org-element-property :contents-begin context)
                              (org-element-property :contents-end context))))
                (unpackaged/org-element-descendant-of 'item context))  ; Element in list item, e.g. a link
            ;; Non-empty item: Add new item.
            (org-insert-item)
          ;; Empty item: Close the list.
          ;; TODO: Do this with org functions rather than operating on the text. Can't seem to find the right function.
          (delete-region (line-beginning-position) (line-end-position))
          (insert "\n"))))

     ((when (fboundp 'org-inlinetask-in-task-p)
        (org-inlinetask-in-task-p))
      ;; Inline task: Don't insert a new heading.
      (org-return))

     ((org-at-table-p)
      (cond ((save-excursion
               (beginning-of-line)
               ;; See `org-table-next-field'.
               (cl-loop with end = (line-end-position)
                        for cell = (org-element-table-cell-parser)
                        always (equal (org-element-property :contents-begin cell)
                                      (org-element-property :contents-end cell))
                        while (re-search-forward "|" end t)))
             ;; Empty row: end the table.
             (delete-region (line-beginning-position) (line-end-position))
             (org-return))
            (t
             ;; Non-empty row: call `org-return'.
             (org-return))))
     (t
      ;; All other cases: call `org-return'.
      (org-return)))))

6.2.2 alphapapa/unpackaged.el: A collection of useful Emacs Lisp code that isn’t substantial enough to be packaged

;;;###autoload
(defun unpackaged/org-sort-multi ()
  "Call `org-sort' until \\[keyboard-quit] is pressed."
  (interactive)
  ;; Not sure if `with-local-quit' is necessary, but probably a good
  ;; idea in case of recursive edit.
  (with-local-quit
    (cl-loop while (call-interactively #'org-sort))))

7 default-setting

7.1 Global

(setq user-full-name "GTrunSec"
      user-mail-address "gtrunsec@hardenedlinux.org")
(setq-default history-length 1000)
(setq create-lockfiles nil)
(require 'org-protocol)

;; (setq browse-url-browser-function 'browse-url-Chrome)
;; https://emacs.stackexchange.com/questions/5603/how-to-quickly-copy-move-file-in-emacs-dired
(setq dired-dwim-target t)

(add-hook! 'dired-mode 'dired-async-mode)
;;(add-hook! 'xah-fly-command-mode-activate-hook 'bookmark-save)
(defun gtrun/truncate-lines-hook ()
  (setq-local truncate-lines nil)
  )

(add-hook! 'text-mode-hook 'gtrun/truncate-lines-hook)

(setenv "XAPIAN_CJK_NGRAM" "1")
(setenv "QT_DEBUG_PLUGINS" "1")
(fset 'yes-or-no-p 'y-or-n-p)

8 Completion

8.1 Ivy/counsel

  (use-package! counsel
    :hook
    (after-init . ivy-mode)
    (counsel-grep-post-action . better-jumper-set-jump)
    :diminish ivy-mode
    :config
    (setq counsel-find-file-ignore-regexp "\\(?:^[#.]\\)\\|\\(?:[#~]$\\)\\|\\(?:^Icon?\\)"
          counsel-describe-function-function #'helpful-callable
          ncounsel-describe-variable-function #'helpful-variable
          ;; Add smart-casing (-S) to default command arguments:
          counsel-rg-base-command "rg -S --no-heading --line-number --color never %s ."
          counsel-ag-base-command "ag -S --nocolor --nogroup %s"
          counsel-pt-base-command "pt -S --nocolor --nogroup -e %s"
          counsel-find-file-at-point t)
       )

     (use-package! ivy-rich
       :config
       (ivy-rich-mode 1)
       (setq ivy-format-function #'ivy-format-function-line))
     ;;[[https://github.com/gilbertw1/better-jumper][gilbertw1/better-jumper: A configurable jump list implementation for Emacs]]

8.2 company

(package! company-lsp)
(use-package! company-lsp)
(after! company
  (setq company-idle-delay 0.5
        company-minimum-prefix-length 2
        company-transformers nil)
  (setq company-show-numbers t)
  (define-key company-active-map (kbd "C-n") 'company-select-next-or-abort)
  (define-key company-active-map (kbd "C-j") 'company-select-previous-or-abort)

  (defun ora-company-number ()
  "Forward to `company-complete-number'.
Unless the number is potentially part of the candidate.
In that case, insert the number."
  (interactive)
  (let* ((k (this-command-keys))
         (re (concat "^" company-prefix k)))
    (if (or (cl-find-if (lambda (s) (string-match re s))
                        company-candidates)
            (> (string-to-number k)
               (length company-candidates))
            (looking-back "[0-9]+\\.[0-9]*" (line-beginning-position)))
        (self-insert-command 1)
      (company-complete-number
       (if (equal k "0")
           10
         (string-to-number k))))))

(defun ora--company-good-prefix-p (orig-fn prefix)
  (unless (and (stringp prefix) (string-match-p "\\`[0-9]+\\'" prefix))
    (funcall orig-fn prefix)))
(advice-add 'company--good-prefix-p :around #'ora--company-good-prefix-p)

(let ((map company-active-map))
  (mapc (lambda (x) (define-key map (format "%d" x) 'ora-company-number))
        (number-sequence 0 9))
  (define-key map " " (lambda ()
                        (interactive)
                        (company-abort)
                        (self-insert-command 1)))
  (define-key map (kbd "<return>") nil)))

8.3 selectrum

(package! selectrum)
(package! selectrum-prescient)
(use-package! selectrum
  :config
  (selectrum-mode +1)
  )
(use-package! selectrum-prescient
  :config
  ;; to make sorting and filtering more intelligent
  (selectrum-prescient-mode +1)
  ;; to save your command history on disk, so the sorting gets more
  ;; intelligent over time
  ;;(prescient-persist-mode +1)
  )

8.4 Customize completion-at-point

;; First try to indent the current line, and if the line
;; was already indented, then try `completion-at-point'
(setq tab-always-indent 'complete)

8.5 company-tabnine

(package! company-tabnine)
(use-package! company-tabnine
  :when (featurep! :completion company)
  :config
  (setq company-tabnine--disable-next-transform nil)
  (defun my-company--transform-candidates (func &rest args)
    (if (not company-tabnine--disable-next-transform)
        (apply func args)
      (setq company-tabnine--disable-next-transform nil)
      (car args)))

  (defun my-company-tabnine (func &rest args)
    (when (eq (car args) 'candidates)
      (setq company-tabnine--disable-next-transform t))
    (apply func args))

  (advice-add #'company--transform-candidates :around #'my-company--transform-candidates)
  (advice-add #'company-tabnine :around #'my-company-tabnine)
  ;; Trigger completion immediately.
  ;; (setq company-idle-delay 0)

  ;; Number the candidates (use M-1, M-2 etc to select completions).
  (setq company-show-numbers t)

  ;; Use the tab-and-go frontend.
  ;; Allows TAB to select and complete at the same time.
  (company-tng-configure-default)
  (setq company-frontends
        '(company-tng-frontend
          company-pseudo-tooltip-frontend
          company-echo-metadata-frontend))
  )

8.6 company-math

(use-package! company-math
  :config
  (defun my-latex-mode-setup ()
  (setq-local company-backends
              (append '((company-math-symbols-latex company-latex-commands))
                      company-backends)))
  )

8.7 company-backend

(set-company-backend! '(julia-mode
                        org-mode)
  '(
    company-math-symbols-unicode
    company-files
    company-yasnippet
    :separate
    company-tabnine
    ))
;;  (set-company-backend! 'sh-mode nil) ; unsets backends for sh-mode
(set-company-backend! '(c-mode
                        c++-mode
                        ess-mode
                        haskell-mode
                        ;;emacs-lisp-mode
                        conf-mode
                        lisp-mode
                        sh-mode
                        php-mode
                        python-mode
                        go-mode
                        ruby-mode
                        rust-mode
                        js-mode
                        css-mode
                        web-mode
                        nix-mode
                        json-mode
                        )
  '(
    company-files
    company-yasnippet
    :separate
    company-tabnine
    ))

(setq +lsp-company-backends '(company-lsp
                              company-files
                              company-yasnippet
                              :separate
                              company-tabnine
                              ))

8.8 Edition

8.8.1 maple-iedit

  (use-package! maple-iedit
    :commands (maple-iedit-match-all maple-iedit-match-next maple-iedit-match-previous)
    :config
    (delete-selection-mode t)
    (setq maple-iedit-ignore-case t)
    (defhydra maple/iedit ()
      ("n" maple-iedit-match-next "next")
      ("t" maple-iedit-skip-and-match-next "skip and next")
      ("T" maple-iedit-skip-and-match-previous "skip and previous")
      ("p" maple-iedit-match-previous "prev"))
    :bind (:map maple-iedit-mode-keymap
                ("C-n" . maple-iedit-match-next)
                ("C-m" . maple-iedit-match-previous)
                ("<down>" . maple-iedit-match-next)
                ("<up>" . maple-iedit-match-previous)
                ("C-," . maple-iedit-skip-and-match-next)
                ("C-." . maple-iedit-skip-and-match-previous)
                ("<right>" . maple-iedit-skip-and-match-next)
                ("<left>" . maple-iedit-skip-and-match-previous)
                )
    )

8.8.2 highlight

(use-package! highlight-indent-guides
:config
(setq highlight-indent-guides-method 'character)
(setq highlight-indent-guides-auto-enabled nil)
(set-face-background 'highlight-indent-guides-even-face "dimgray")
(set-face-foreground 'highlight-indent-guides-character-face "dimgray")
)

8.8.3 parentheses

;;; -*- lexical-binding: t; -*-
;; we will call `blink-matching-open` ourselves...

(remove-hook 'post-self-insert-hook
             #'blink-paren-post-self-insert-function)
;; this still needs to be set for `blink-matching-open` to work
(setq blink-matching-paren 'show)

(let ((ov nil)) ; keep track of the overlay
  (advice-add
   #'show-paren-function
   :after
    (defun show-paren--off-screen+ (&rest _args)
      "Display matching line for off-screen paren."
      (when (overlayp ov)
        (delete-overlay ov))
      ;; check if it's appropriate to show match info,
      ;; see `blink-paren-post-self-insert-function'
      (when (and (overlay-buffer show-paren--overlay)
                 (not (or cursor-in-echo-area
                          executing-kbd-macro
                          noninteractive
                          (minibufferp)
                          this-command))
                 (and (not (bobp))
                      (memq (char-syntax (char-before)) '(?\) ?\$)))
                 (= 1 (logand 1 (- (point)
                                   (save-excursion
                                     (forward-char -1)
                                     (skip-syntax-backward "/\\")
                                     (point))))))
        ;; rebind `minibuffer-message' called by
        ;; `blink-matching-open' to handle the overlay display
        (cl-letf (((symbol-function #'minibuffer-message)
                   (lambda (msg &rest args)
                     (let ((msg (apply #'format-message msg args)))
                       (setq ov (display-line-overlay+
                                 (window-start) msg ))))))
          (blink-matching-open))))))

(defun display-line-overlay+ (pos str &optional face)
  "Display line at POS as STR with FACE.

FACE defaults to inheriting from default and highlight."
  (let ((ol (save-excursion
              (goto-char pos)
              (make-overlay (line-beginning-position)
                            (line-end-position)))))
    (overlay-put ol 'display str)
    (overlay-put ol 'face
                 (or face '(:inherit default :inherit highlight)))
    ol))

(setq show-paren-style 'paren
      show-paren-delay 0.03
      show-paren-highlight-openparen t
      show-paren-when-point-inside-paren nil
      show-paren-when-point-in-periphery t)
(show-paren-mode 1)

8.8.4 awesome-pair

(use-package! awesome-pair)

8.8.5 hungry-delete

(package! hungry-delete)
(use-package! hungry-delete
  :config
  (add-hook! 'after-init-hook #'global-hungry-delete-mode)
)

8.9 Bookmark

(package! bm)
  (use-package! bm
    :demand t
    :init
    (setq bm-restore-repository-on-load t)
    :config

    (bind-keys
     :map bm-show-mode-map
     ("j" . next-line)
     ("k" . previous-line))

    (setq bm-cycle-all-buffers t
          bm-highlight-style 'bm-highlight-only-fringe
          bm-repository-size 1000)
    (setq-default bm-buffer-persistence t)

    (defun adq/bm-save ()
      "Save bookmarks to persistent repository."
      (interactive)
      (bm-buffer-save-all)
      (bm-repository-save))

    (advice-add 'bm-bookmark-add
                :after (lambda (&rest args)
                         (adq/bm-save)))
    (advice-add 'bm-bookmark-remove
                :after (lambda (&rest args)
                         (adq/bm-save)))
    (add-hook 'after-init-hook #'bm-repository-load)
    (add-hook 'find-file-hooks #'bm-buffer-restore)
    (add-hook 'after-rever-hook #'bm-buffer-restore)
    (add-hook 'kill-buffer-hook #'bm-buffer-save)
    (add-hook 'after-save-hook #'bm-buffer-save)
    (add-hook 'kill-emacs-hook
              (lambda ()
                (bm-buffer-save-all)
                (bm-repository-save)))

    (defun adq/bm-list-all-bookmarks ()
      "Generate a list of all bookmarks from all files."
      (let ((bookmarks '()))
        (cl-loop for entry in bm-repository
                 when (and (listp entry) (f-readable-p (car entry)))
                 do
                 (with-temp-buffer
                   (insert-file-contents-literally (car entry))
                   (cl-letf (((symbol-function 'bm-bookmark-add)
                              (lambda (&optional annotation time temporary)
                                (!cons (list (car entry)
                                             (point)
                                             (line-number-at-pos)
                                             (string-trim (thing-at-point 'line t)))
                                       bookmarks)))
                             ((symbol-function 'message)
                              (lambda (&rest _))))
                     (bm-buffer-restore-2 (cdr entry)))))
        bookmarks))

      (defun adq/helm-bm-all-format-bookmark (bookmark)
        "Format bookmark for display."
        (let ((file (f-filename (car bookmark)))
              (line (caddr bookmark))
              (contents (cadddr bookmark)))
          (cons
           (format "%s:%s: %s"
                   (propertize file 'face compilation-info-face)
                   (propertize (format "%d" line) 'face compilation-line-face)
                   contents)
           bookmark)))

      (defvar adq/helm-bm-all-source
        (helm-build-sync-source "Helm All Bookmarks"
          :candidates
          (lambda ()
            (mapcar #'adq/helm-bm-all-format-bookmark
                    (adq/bm-list-all-bookmarks)))
          :action
          '(("Switch to buffer" .
             (lambda (bookmark)
               (find-file (car bookmark))
               (goto-char (cadr bookmark))))))
        "Helm source with all the bookmarks.")

      (defun adq/helm-bm-list-all ()
        "List all bookmarks usin Helm."
        (interactive)
        (helm :sources 'adq/helm-bm-all-source
              :buffer "*helm bm all*"))

    (defhydra adq/hydra-bm nil
      "
  Bookmarks
  ^^^^------------------------------------------------
  _m_: Toggle      _l_: Bookmarks from Buffers
  _n_: Next        _a_: Bookmarks form All Files
  _p_: Previous    _L_: List
  "
      ("m" bm-toggle)
      ("n" bm-next)
      ("p" bm-previous)
      ("a" adq/helm-bm-list-all :exit t)
      ("l" helm-bm :exit t)
      ("L" bm-show-all :exit t))
    (bind-key "C-c m" #'adq/hydra-bm/body))

8.10 scroll

;; (use-package! fast-scroll
;; :config
;; (setq fast-scroll-throttle 0.5)
;; (add-hook 'fast-scroll-start-hook (lambda () (flycheck-mode -1)))
;; (add-hook 'fast-scroll-end-hook (lambda () (flycheck-mode 1)))
;; (fast-scroll-config)
;; (fast-scroll-mode 1)
;; )
(use-package! scrollkeeper)
(global-set-key [remap scroll-up-command] #'scrollkeeper-contents-up)
(global-set-key [remap scroll-down-command] #'scrollkeeper-contents-down)

8.11 templating

(package! yatemplate)
(use-package! yatemplate
  :after yasnippet
  :config
  ;; Define template directory
  (setq yatemplate-dir (concat doom-private-dir "modules/templates"))
  ;; Coupling with auto-insert
  (setq auto-insert-alist nil)
  (yatemplate-fill-alist)
  (add-hook 'find-file-hook 'auto-insert)
  )

9 org-mode

9.1 load basic config

(load! "setting")
(use-package! ox-hugo)
(use-package! ob-session-async)
(use-package! ob-async)

9.2 Only modes or files seeting in org-mode

(define-derived-mode only-file-to-org-mode org-mode "Org + only mode"
  "Only modes for org file."
  (add-hook! org-tanglesync-watch-mode :local #'org-tanglesync-mode)
  )
(add-to-list 'auto-mode-alist '("README-[^z-a]*\\.org\\'" . only-file-to-org-mode))

9.3 org-setting

(setq org-clock-into-drawer t)
(add-hook! 'org-mode-hook 'auto-revert-mode)
(add-hook! 'dired-mode-hook 'org-download-enable)
;; (setq-hook! 'org-mode-hook fill-column 80)
;; (setq-hook! 'org-mode-hook org-superstar-mode 1)
(setq org-directory "~/Documents/org-notes")
(setq org-log-into-drawer t)
(setq org-agenda-start-day "-1d")
(setq org-agenda-span 2)
(setq org-time-clocksum-format '(:hours "%d" :require-hours t :minutes ":%02d" :require-minutes t))
(setq org-archive-location (concat "%s_archive_" (format-time-string "%Y" (current-time)) "::"))
;; Removes clocked tasks with 0:00 duration
(setq org-clock-out-remove-zero-time-clocks t)
;; Change task state to STARTED when clocking in
(setq org-clock-in-switch-to-state "⚔ INPROCESS")
(setq org-src-fontify-natively t
      org-src-preserve-indentation t
      org-src-tab-acts-natively t
      org-src-window-setup 'current-window)
(setq org-agenda-time-leading-zero t)
;;Markdown
(eval-after-load "org"
  '(require 'ox-md nil t))
;;https://orgmode.org/worg/org-contrib/babel/examples/fontify-src-code-blocks.html

(defun org-show-two-levels ()
  (interactive)
  (org-content 2))

(add-hook! 'org-mode-hook 'org-show-two-levels)

9.4 org-mode-map && after org setting

(after! org
  (when IS-LINUX
    (setq org-id-locations-file (concat org-directory "/cache/.linux-orgids"))
    )

  (when IS-MAC
    (setq org-id-locations-file (concat org-directory "/cache/.mac-orgids"))
  )
  (setq org-download-timestamp "%Y%m%d_%H%M%S")
  (add-hook! 'unpackaged/org-return-dwim 'unpackaged/org-fix-blank-lines)
  (define-key org-mode-map (kbd "C-c ;") 'org-time-stamp-inactive)
  (define-key org-mode-map (kbd "RET") 'unpackaged/org-return-dwim)
  (setq org-plantuml-jar-path (expand-file-name "~/.myscript/plantuml"))

)

9.5 org-starter

(package! org-starter)
(setq org-agenda-files (list "~/Documents/org-notes/braindump"))

(use-package! org-starter
  :custom
  ;; Enable external configuration files loaded from org-starter-path
  (org-starter-load-config-files t)
  :config
  (org-starter-def "~/Documents/org-notes"
                   :files
                   ("braindump/private-org/GTD/gtd.org"                      :agenda t :key "g" :refile (:maxlevel . 5))
                   ("braindump/private-org/GTD/notes.org"                    :agenda t :key "n" :refile (:maxlevel . 5 ))
                   ("braindump/private-org/GTD/myself.org"                   :agenda t :key "m" :refile (:maxlevel . 5 ))
                   ("braindump/private-org/GTD/Habit.org"                    :agenda t :key "h" :refile (:maxlevel . 5 ))
                   ("posts/myself/love.org"         :key "l" :refile (:maxlevel . 5 ))
                   ("posts/myself/qing.org"         :key "q" :refile (:maxlevel . 5 ))
                   ("posts/myself/plan.org"         :key "p" :refile (:maxlevel . 5 ))
                   ("elfeed.org"         :key "e" :refile (:maxlevel . 5 ))
                   ("braindump/GuangTao-owner/learn-music.org"          :agenda t :key "M" :refile (:maxlevel . 5 ))
                   ("braindump//GuangTao-owner/GuangTao-library.org"       :key "b" :refile (:maxlevel . 5 ))
                   ("braindump/life/life-goods.org"     :key "s" :refile (:maxlevel . 5 ))
                   )
  (org-starter-def "~/.config/nixpkgs/dotfiles/doom-emacs/"
                   :files
                   ("config.org" :key "c" :refile (:maxlevel . 5))
                   ("xah-fly-keys.org" :key "x" :refile (:maxlevel . 5))
                   ;;("nix.org" :key "x" :refile (:maxlevel . 5))
                   )
  (org-starter-def "~/.config/nixpkgs"
                   :files
                   ("README.org")
                   ("global-readme.org")
                   ("dotfiles/wallpaper/wallpaper.org" :agenda nil)
                   )

 (defhydra gtrun/hydra-org-starter nil
   "
  Org-starter-files
  ^^^^------------------------------------------------
 _c_: config.org  _g_: gtd.org     _l_: love.org
 _n_: note        _h_: Habit.org    _x_: xah-fly-keys.org
 _m_: myself      _p_: Plan.org
 _b_: my-books    _e_: elfeed
 _s_: my-life
  "

      ("c" org-starter-find-file:config)
      ("x" org-starter-find-file:xah-fly-keys)
      ("g" org-starter-find-file:gtd)
      ("s" org-starter-find-file:life-goods)
      ("n" org-starter-find-file:notes)
      ("e" org-starter-find-file:elfeed)
      ("m" org-starter-find-file:myself)
      ("l" org-starter-find-file:love)
      ("h" org-starter-find-file:Habit)
      ("p" org-starter-find-file:plan)
      ("b" org-starter-find-file:GuangTao-library)
)
:commands org-starter-load-all-files-in-path
:hook
(after-init . org-starter-load-all-files-in-path)
 :bind
 (
  ("C-c e" . org-starter-select-file))
 ;; "C-c e" . org-starter-refile-by-key))
 )

9.6 org-superstar

(package! org-superstar)
(use-package! org-superstar
  :config
  (add-hook 'org-mode-hook (lambda () (org-superstar-mode 1)))
  (setq org-superstar-headline-bullets-list '("☰" "☷" "☵" "☲"  "☳" "☴"  "☶"  "☱" ))
)

9.7 org-ql

(package! org-ql :recipe (:host github :repo "alphapapa/org-ql"
                         :files ("*.el")
                         ))
(use-package! org-ql)
(package! helm-org-rifle)
(use-package! helm-org-rifle)

9.8 org-book

(package! org-books :recipe (:host github :repo "lepisma/org-books"))
(use-package! org-books
  :config
  (setq org-books-file "~/Documents/org-notes/braindump/GuangTao-owner/GuangTao-library.org")
  )

9.9 org-z

  • [2021-01-08 Fri 17:49] -> helm-rg
  • [2021-01-08 Fri 17:49] -> org-ql
(package! org-z :recipe (:host github :repo "landakram/org-z"
                         :files ("*.el")
                         ))
(use-package! org-z
  :init
  (define-key org-mode-map (kbd "C-c C-;") 'org-z-insert-link)
  ;;(require 'org-z-helm)
  (require 'org-z-selectrum)
  :config
  (org-z-mode 1)
  (setq org-z-directories  '("~/Documents/org-notes/braindump"
                             "~/Documents/org-notes/braindump/GuangTao-owner"
                             "~/Documents/org-notes/braindump/journals"
                             "~/Documents/org-notes/braindump/CS"
                             "~/Documents/org-notes/braindump/network"
                             "~/Documents/org-notes/braindump/security"
                             "~/Documents/org-notes/braindump/life"
                             "~/Documents/org-notes/braindump/math"
                             "~/Documents/org-notes/braindump/math/my-mathematic-julia"
                             "~/Documents/org-notes/braindump/data-science"
                             "~/Documents/org-notes/braindump/deployment"
                             "~/Documents/org-notes/braindump/hardware"
                             "~/Documents/org-notes/braindump/emacs"
                             "~/Documents/org-notes/braindump/gaming"
                             "~/Documents/org-notes/braindump/financial"
                             "~/Documents/org-notes/braindump/private-org"
                             "~/Documents/org-notes/braindump/private-org/GTD"
                             "~/Documents/org-notes/braindump/nix"
                             "~/Documents/org-notes/braindump/programming"
                             "~/.config/nixpkgs/dotfiles/doom-emacs"
                             ))

   )

9.10 GTD

9.10.1 agenda knowledge

  1. Org Mode - Organize Your Life In Plain Text!

    [2020-10-13 Tue 15:05] <- Org Edna

  2. Sexp Entries and the Fancy Diary Display

9.10.2 super-agenda

(package! org-super-agenda)
(use-package! org-super-agenda
  :config
  (add-hook! 'after-init-hook 'org-super-agenda-mode)
  (require 'org-habit)
  (setq
   org-agenda-skip-scheduled-if-done t
   org-agenda-skip-deadline-if-done t
   org-agenda-include-deadlines t
   org-agenda-include-diary nil
   org-agenda-block-separator nil
   org-agenda-compact-blocks t
   org-agenda-start-with-log-mode t)
  )

9.10.3 org-todo-keywords

    (setq org-todo-keywords
     '((sequence
           "TODO(t)"  ; A task that needs doing & is ready to do
           "PROJ(p)"  ; An ongoing project that cannot be completed in one step
           "INPROCESS(s)"  ; A task that is in progress
           "⚑ WAITING(w)"  ; Something is holding up this task; or it is paused
           "|"
           "☟ NEXT(n)"
           "✰ IMPORTANT(i)"
           "DONE(d)"  ; Task successfully completed
           "✘ CANCELED(c@)") ; Task was cancelled, aborted or is no longer applicable
          (sequence
           "✍ NOTE(N)"
           "FIXME(f)"
           "☕ BREAK(b)"
           "❤ LOVE(l)"
           "REVIEW(r)"
           )) ; Task was completed
        org-todo-keyword-faces
        '(
          ("TODO" . (:foreground "#ff39a3" :weight bold))
          ("INPROCESS"  . "orangered")
          ("✘ CANCELED" . (:foreground "white" :background "#4d4d4d" :weight bold))
          ("⚑ WAITING" . "pink")
          ("☕ BREAK" . "gray")
          ("❤ LOVE" . (:foreground "VioletRed4"
                                   ;; :background "#7A586A"
                                   :weight bold))
          ("☟ NEXT" . (:foreground "DeepSkyBlue"
                                   ;; :background "#7A586A"
                                      :weight bold))
          ("✰ IMPORTANT" . (:foreground "greenyellow"
                                      ;; :background "#7A586A"
                                      :weight bold))
          ("DONE" . "#008080")
          ("FIXME" . "IndianRed")
          ))

9.10.4 agenda-custom-setting

(require 'org-super-agenda)
(setq org-agenda-custom-commands
      '(("z" "GtruN Agenda"
         ((agenda "" ((org-agenda-span 2)
                      (org-agenda-start-day "-1d")
                      (org-super-agenda-groups
                       '((:name "Today List"
                                :time-grid t
                                :date today
                                :todo "⚔ INPROCESS"
                                :scheduled today
                                :order 1)))))
          (alltodo "" ((org-agenda-overriding-header "")
                       (org-super-agenda-groups
                        '((:name "Next to do"
                                 :priority>= "B"
                                 :order 2)
                          (:name "Important"
                                 :todo "✰ Important"
                                 :order 6)
                          (:name "Due Today"
                                 :deadline today
                                 :order 3)
                          (:name "Due Soon"
                                 :deadline future
                                 :order 8)
                          (:name "Overdue"
                                 :deadline past
                                 :order 20)
                          (:name "Issues"
                                 :tag "Issue"
                                 :order 12)
                          (:name "Projects"
                                 :tag "Project"
                                 :order 14)
                          (:name "Emacs"
                                 :tag "Emacs"
                                 :order 13)
                          (:name "Research"
                                 :tag "Research"
                                 :order 15)
                          (:name "To read"
                                 :tag ("BOOK" "READ")
                                 :order 30)
                          (:name "Waiting"
                                 :todo "⚑ WAITING"
                                 :order 18)
                          (:name "trivial"
                                 :priority<= "C"
                                 :todo ("SOMEDAY")
                                 :order 90)
                          (:discard (:tag ("Chore" "Routine" "Daily")))))))))

        ("b" . "BOOK")

        ("bb" "Search tags in todo, note, and archives"
         search "+{:book\\|books:}")

        ("bd" "BOOK TODO List"
         search "+{^\\*+\\s-+\\(⚔ INPROCESS\\|TODO\\|⚑ WAITING\\)\\s-} +{:book\\|books:}")

        ("d" "ALL DONE OF TASKS"
         search "+{^\\*+\\s-+\\(✔ DONE\\|✘ CANCELED\\)\\s-}")

        ("i" "ALL INPROCESS OF TASKS"
         search "+{^\\*+\\s-+\\(⚔ INPROCESS\\)\\s-}")

        ))

9.10.5 ✰ IMPORTANT Org Edna

[2020-10-13 Tue 15:05] -> Org Mode - Organize Your Life In Plain Text!

  • native-compiler-error
(package! org-edna :recipe (:no-byte-compile t))
(use-package! org-edna
  :config
  (add-hook! 'after-init-hook 'org-edna-mode)
)

9.10.6 org-wild-notifier

(package! org-wild-notifier)
(use-package! org-wild-notifier
  :defer t
  :config
  (add-hook! 'after-init-hook 'org-wild-notifier-mode)
  (setq ;;org-wild-notifier-alert-time 15
        alert-default-style (if IS-MAC 'osx-notifier 'libnotify)))

9.11 Org-babel

(after! ob-async
  (setq ob-async-no-async-languages-alist '("ipython" "ein-python"
                                            "ein-rust"
                                            "ein-julia"
                                            "ein-haskell"
                                            ))
  )

;;[[https://stackoverflow.com/questions/22668112/how-to-evaluate-all-code-blocks-when-exporting-in-emacs-org-mode][How to evaluate all code blocks when exporting in emacs org-mode - Stack Overflow]]
(setq org-confirm-babel-evaluate nil)
(setq org-export-use-babel nil)

(setq org-babel-C++-compiler 'clang++)
(setq org-babel-C-compiler 'clang)
gcc-9

9.12 org-publish

;;; setting.el -*- lexical-binding: t; -*-
  (setq org-publish-project-alist
        '(("nsm"
           :base-directory "~/Documents/org-notes/NSM-GTD"
           :with-author "GTrunSec"
           :publishing-function org-html-publish-to-html
           :publishing-directory "~/Documents/my-blog/public/custom"
           :exclude "README.org"
           )
          ("my-learning"
           :base-directory "~/Documents/org-publish"
           :publishing-function org-html-publish-to-html
           :publishing-directory "~/Documents/my-blog/public/custom"
           :exclude "README.org"
           )
          ("init"
           :base-directory "~/.config/nixpkgs/dotfiles/doom-emacs"
           :publishing-function org-html-publish-to-html
           :publishing-directory "~/Documents/my-blog/public/custom"
           )
          ("jupyter-math"
           :base-directory "~/Dropbox/Drop-project/my-mathematic-env/math"
           :publishing-function org-html-publish-to-html
           :publishing-directory "~/Documents/my-blog/public/custom"
           )
          ("art"
           :base-directory "~/Documents/org-notes/art"
           :publishing-function org-html-publish-to-html
           :publishing-directory "~/Documents/my-blog/public/custom"
           )
          ("course"
           :base-directory "~/Documents/org-notes/course"
           :publishing-function org-html-publish-to-html
           :publishing-directory "~/Documents/my-blog/public/custom"
           )
          ))

9.13 org-crypt

;; 當被加密的部份要存入硬碟時,自動加密回去
  ;; 設定要加密的 tag 標籤為 secret
  (setq org-crypt-tag-matcher "secret")

  ;; 避免 secret 這個 tag 被子項目繼承 造成重複加密
  ;; (但是子項目還是會被加密喔)
  (setq org-tags-exclude-from-inheritance (quote ("secret")))

  ;; 用於加密的 GPG 金鑰
  ;; 可以設定任何 ID 或是設成 nil 來使用對稱式加密 (symmetric encryption)
  (setq org-crypt-key nil)

9.14 org-notdeft

(package! notdeft :recipe (:host github :repo "hasu/notdeft"))
(use-package! notdeft
  :config
  (setq notdeft-extension "org")
  ;;(setq notdeft-secondary-extensions '("md" "org" "scrbl"))
  (setq notdeft-xapian-program "/home/gtrun/.nix-profile/bin/notdeft-xapian")
  (when IS-MAC
    (setq notdeft-xapian-program "/Users/gtrun/.nix-profile/bin/notdeft-xapian")
    )
  (setq notdeft-directories '("~/Documents/org-notes/post/myself"
                              "~/Documents/org-notes/dailies"
                              "~/Documents/org-notes/post/traveling"
                              "~/Documents/org-notes/post/agenda"
                              "~/Documents/org-notes/post/game"
                              "~/Dropbox/project/my-learning-list"
                              "~/Documents/org-notes/GTD"
                              "~/Documents/org-notes/art"
                              "~/Documents/org-notes/braindump"
                              ))

  :bind (:map notdeft-mode-map
         ("C-q" . notdeft-quit)
         ("C-r" . notdeft-refresh)
         )
  )
  • build

cd ~/.emacs.d/.local/straight/repos/notdeft/xapian make

9.16 org-properties

9.17 org-timestramp

9.17.1 export

  • org-export-with-planning #+OPTIONS: p:t

9.18 org-roam

9.18.1 idea

  1. ✍ NOTE tilmanrassy/emacs-treeview: Abstract Emacs Lisp framework for tree navigation

    easy way to display org-ref with tree view instead of org-mode ?

9.18.2 org-roam

(unpin! org-roam)
(use-package! org-roam
  :init
  (require 'org-roam-protocol)
  :config
  ;;(setq org-roam-directory nil)
  ;;https://github.com/zaeph/.emacs.d/blob/0f4bf9a500ef6397b93c41cb51602bea9ab9a4c3/init.el#L3804
  ;; [[https://copingmechanism.com/2020/keeping-org-roam-daily-notes-in-a-separate-folder/][Keeping Org-roam Daily Notes in a separate folder – Coping Mechanism]]
(setq org-roam-dailies-capture-templates '(("d" "daily" plain (function org-roam-capture--get-point) ""
                                            :immediate-finish t
                                            :file-name "dailies/%<%Y-%m-%d>-${slug}"
                                            :head "#+TITLE: %<%Y-%m-%d>-${slug}\n#+created: %u\n#+last_modified: %U\n\n")))
)

9.18.3 org-roam-server

(package! org-roam-server)
(use-package! org-roam-server
  :config
  (setq org-roam-server-port 8081
        org-roam-server-export-inline-images t
        org-roam-server-authenticate nil
        org-roam-server-network-poll t
        org-roam-server-network-arrows nil
        org-roam-server-network-label-truncate t
        org-roam-server-network-label-truncate-length 60
        org-roam-server-network-label-wrap-length 20))

9.18.4 org-roam-bibtex

(package! org-roam-bibtex)
(use-package! org-roam-bibtex
  :config
  (add-hook 'org-mode-hook 'org-roam-bibtex-mode)
  :bind (:map org-roam-bibtex-mode-map
              ("C-c n a" . orb-note-actions)
              )
  )

9.18.5 org-ref

(package! org-ref)
(use-package! org-ref
  :config
  (defsubst dnd-unescape-uri (uri)
  (replace-regexp-in-string
   "%[A-Fa-f0-9][A-Fa-f0-9]"
   (lambda (arg)
     (let ((str (make-string 1 0)))
       (aset str 0 (string-to-number (substring arg 1) 16))
       str))
   uri t t))
  (setq org-ref-default-bibliography '("~/Documents/org-notes/braindump/bibliography/myBibliography.bib"))
  (setq bibtex-completion-bibliography "~/Documents/org-notes/braindump/bibliography/myBibliography.bib")
  )

9.18.6 org-templates

(defun org-roam-dailies-capture-today ()
  "Capture a note into the daily note for today."
  (interactive)
  (let ((org-roam-capture-templates org-roam-dailies-capture-templates)
        (org-roam-capture--info (list (cons 'time (current-time))))
        (org-roam-capture--context 'dailies))
    (org-roam--capture)))

(setq org-capture-templates '(("n" "Note" entry (function org-roam-dailies-capture-today)
                                 "* %?\n")))

9.19 ob-mermaid

(package! ob-mermaid)
(use-package! ob-mermaid
  :config
  (setq ob-mermaid-cli-path "~/.nix-profile/bin/mmdc")
  )

9.20 org-spacer   edit

(package! org-spacer.el :recipe (:host github :repo "dustinlacewell/org-spacer.el"))
;; (use-package! org-spacer
;;   :config
;;   ;; (add-hook 'org-mode-hook
;;   ;;           (lambda () (add-hook 'before-save-hook
;;   ;;                                'org-spacer-enforce nil 'make-it-local)))
;;   )

9.21 org-density.el   summary statistic

(package! org-treeusage :recipe (:host github :repo "mtekman/org-treeusage.el"))
(use-package! org-treeusage
  :config
  (define-key org-mode-map (kbd "C-c d") 'org-treeusage-mode)
  )

9.22 org-format

9.22.1 org-link-type

(defun endless/export-audio-link (path desc format)
  "Export org audio links to hmtl."
  (cl-case format
    (html (format
       "<audio preload=\"auto\"> <source src=\"https://www.gtrun.org/music/%s\">%s</audio>"
       path (or desc "")))

    ;; README: hugo music file path
    (md (format
     "<audio class=\"wp-audio-shortcode\"  loop=\"1\"  preload=\"auto\" style=\"width: 100%%;\" controls> <source src=\"https://www.gtrun.org/music/%s\">%s</audio>"
     path (or desc "")))
    (latex (format "(HOW DO I EXPORT AUDIO TO LATEX? \"%s\")" path))))

(after! org
  (org-add-link-type "audio" #'ignore #'endless/export-audio-link)
  ;;(setq org-download-timestamp "%Y%m%d_%H%M%S")
)

9.23 org-super-links

(package! org-super-links :recipe (:host github
                       :repo "toshism/org-super-links"
                       :files ("*.el")
                       ))
(use-package! org-super-links
  :config
  (defun org-super-links-backlink-prefix-timestamp ()
  "Return the default prefix string for a backlink.
Inactive timestamp formatted according to `org-time-stamp-formats' and
a separator ' <- '."
  (let* ((time-format (substring (cdr org-time-stamp-formats) 1 -1))
         (time-stamp (format-time-string time-format (current-time))))
    (format " - [%s] <- "
            time-stamp)))

(defun org-super-links-link-prefix-timestamp ()
  "Return the default prefix string for a backlink.
Inactive timestamp formatted according to `org-time-stamp-formats' and
a separator ' -> '."
  (let* ((time-format (substring (cdr org-time-stamp-formats) 1 -1))
         (time-stamp (format-time-string time-format (current-time))))
    (format " - [%s] -> "
            time-stamp)))


(defun org-super-links-quick-insert-inline-link ()
  (interactive)
  ;; how to handle prefix here?
  (let ((org-super-links-related-into-drawer nil)
        (org-super-links-link-prefix 'org-super-links-backlink-prefix-timestamp))
    (org-super-links-link)))

(defun org-super-links-quick-insert-drawer-link ()
  (interactive)
  ;; how to handle prefix here?
  (let ((org-super-links-related-into-drawer (or org-super-links-related-into-drawer t))
        (org-super-links-link-prefix 'org-super-links-link-prefix-timestamp))
    (org-super-links-link)))

(setq org-id-link-to-org-use-id
        'create-if-interactive-and-no-custom-id)

  (setq org-super-links-related-into-drawer nil
        org-super-links-backlink-into-drawer nil
        org-super-links-link-prefix 'org-super-links-link-prefix-timestamp)
  )

9.24 org-wiki

(package! wikinfo :recipe (:host github
                             :repo "progfolio/wikinfo"
                             ))

(package! wikinforg :recipe (:host github
                             :repo "progfolio/wikinforg"
                             ))

(use-package! wikinfo)
(use-package! wikinforg)

9.25 org-noter-plus

(package! org-noter-plus :recipe (:host github :repo "yuchen-lea/org-noter-plus"))
(use-package! org-noter-plus
  :config
  (setq org-noter-plus-image-dir "~/Documents/org-notes/braindump/.attach")
)

9.26 org-noter-plus

(package! ox-ipynb :recipe (:host github :repo "jkitchin/ox-ipynb"))
(use-package! ox-ipynb)

9.28 stardiviner/org-link-beautify: Beautify org links with colors and icons.

(package! org-link-beautify :recipe (:host github
                             :repo "stardiviner/org-link-beautify"
                             ))

(use-package! org-link-beautify
  :config
  (when IS-LINUX
   (add-hook! 'org-mode-hook 'org-link-beautify-mode))
  )

9.29 TODO marcIhm/org-working-set: Manage a working-set of org-nodes   manage

(package! org-working-set
)
(use-package! org-working-set)

9.30 mtekman/org-tanglesync.el: A package to pull external changes into an org-mode source block if that block is tangled to an external file

(package! org-tanglesync)
(use-package! org-tanglesync
  :config
  :hook (((prog-mode text-mode) . org-tanglesync-watch-mode))
  :custom
  (org-tanglesync-watch-files '("~/.config/nixpkgs/dotfiles/README-dotfiles.org"
                                "~/.config/nixpkgs/README-home-manager.org"
                                "~/.config/nixpkgs/nixos-flk/README-NixOS.org"
                                ))
  :config
  ;; (add-hook 'org-mode-hook (lambda ()
  ;;                            ;;……
  ;;                            (cond
  ;;                             ((equal (substring buffer-file-name -11) "-README.org")
  ;;                              (progn
  ;;                                (setq-local org-tanglesync-mode t)
  ;;                                ))
  ;;                              ))
  ;;                            )

  :bind
  (( "C-c M-i" . org-tanglesync-process-buffer-interactive)
   ( "C-c M-a" . org-tanglesync-process-buffer-automatic))
  )

9.33 alphapapa/org-graph-view: View Org buffers as a clickable, graphical mind-map

;; (package! org-graph-view :recipe (:host github :repo "alphapapa/org-graph-view"))

;;(use-package! org-graph-view)

9.34 the-humanities/org-mind-map: This is an emacs package that creates graphviz directed graphs.

(package! org-mind-map :recipe (:host github :repo "the-humanities/org-mind-map"))
(use-package! org-mind-map
  :init
  (require 'ox-org)
  :config
  (setq org-mind-map-engine "circo")
  )
t

9.35 org-parse

10 my-codes

10.1 packages

;;; modules/private/my-code/packages/packages.el -*- lexical-binding: t; -*-
;;; config..el -*- lexical-binding: t; -*-

10.2 lsp

(unpin! lsp-mode)
(use-package! lsp-mode
  :config
  ;; (add-to-list 'lsp-language-id-configuration '(nix-mode . "nix"))
  ;; (lsp-register-client
  ;;  (make-lsp-client :new-connection (lsp-stdio-connection '("rnix-lsp"))
  ;;                   :major-modes '(nix-mode)
  ;;                   :server-id 'nix))
 ;; Support LSP in Org Babel with header argument `:file'.
  ;; https://github.com/emacs-lsp/lsp-mode/issues/377
  (defvar org-babel-lsp-explicit-lang-list
    '("java")
    "Org Mode Babel languages which need explicitly specify header argument :file.")
  (cl-defmacro lsp-org-babel-enbale (lang)
    "Support LANG in org source code block."
    ;; (cl-check-type lang symbolp)
    (let* ((edit-pre (intern (format "org-babel-edit-prep:%s" lang)))
           (intern-pre (intern (format "lsp--%s" (symbol-name edit-pre)))))
      `(progn
         (defun ,intern-pre (info)
           (let ((lsp-file (or (->> info caddr (alist-get :file))
                               buffer-file-name
                               (unless (member ,lang org-babel-lsp-explicit-lang-list)
                                 (concat (org-babel-temp-file (format "lsp-%s-" ,lang))
                                         (cdr (assoc ,lang org-babel-tangle-lang-exts)))))))
             (setq-local buffer-file-name lsp-file)
             (setq-local lsp-buffer-uri (lsp--path-to-uri lsp-file))
             (lsp)))
         (if (fboundp ',edit-pre)
             (advice-add ',edit-pre :after ',intern-pre)
           (progn
             (defun ,edit-pre (info)
               (,intern-pre info))
             (put ',edit-pre 'function-documentation
                  (format "Add LSP info to Org source block dedicated buffer (%s)."
                          (upcase ,lang))))))))

  (defvar org-babel-lsp-lang-list
    '("shell"
      "python"
      "ein"
      ;; "ruby"
      "js" "css"
      "haskell"
      ;; "C" "C++"

      "rust" "go" "java"))

  (dolist (lang org-babel-lsp-lang-list)
    (eval `(lsp-org-babel-enbale ,lang))))

10.3 Latex

(load! "my-latex")

10.3.1 auctex

10.3.2 chinese-latex

(after! latex
      (add-to-list 'org-latex-classes '("article" "\\documentclass[a4paper,11pt]{article}
        [NO-DEFAULT-PACKAGES]
          \\usepackage[utf8]{inputenc}
          \\usepackage[T1]{fontenc}
          \\usepackage{fixltx2e}
          \\usepackage{graphicx}
          \\usepackage{longtable}
          \\usepackage{float}
          \\usepackage{wrapfig}
          \\usepackage{rotating}
          \\usepackage[normalem]{ulem}
          \\usepackage{amsmath}
          \\usepackage{textcomp}
          \\usepackage{marvosym}
          \\usepackage{wasysym}
          \\usepackage{amssymb}
          \\usepackage{booktabs}
          \\usepackage[colorlinks,linkcolor=black,anchorcolor=black,citecolor=black]{hyperref}
          \\tolerance=1000
          \\usepackage{listings}
          \\usepackage{xcolor}
          \\usepackage{fontspec}
          \\usepackage{xeCJK}
          \\setCJKmainfont{Weibei SC}
          \\setmainfont{Fantasque Sans Mono}
          \\lstset{
          %行号
          numbers=left,
          %背景框
          framexleftmargin=10mm,
          frame=none,
          %背景色
          %backgroundcolor=\\color[rgb]{1,1,0.76},
          backgroundcolor=\\color[RGB]{245,245,244},
          %样式
          keywordstyle=\\bf\\color{blue},
          identifierstyle=\\bf,
          numberstyle=\\color[RGB]{0,192,192},
          commentstyle=\\it\\color[RGB]{0,96,96},
          stringstyle=\\rmfamily\\slshape\\color[RGB]{128,0,0},
          %显示空格
          showstringspaces=false
          }
          "
                                        ("\\section{%s}" . "\\section*{%s}")
                                        ("\\subsection{%s}" . "\\subsection*{%s}")
                                        ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
                                        ("\\paragraph{%s}" . "\\paragraph*{%s}")
                                        ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))

      ;; {{ export org-mode in Chinese into PDF
      ;; @see http://freizl.github.io/posts/tech/2012-04-06-export-orgmode-file-in-Chinese.html
      ;; and you need install texlive-xetex on different platforms
      ;; To install texlive-xetex:
      ;;    `sudo USE="cjk" emerge texlive-xetex` on Gentoo Linux
      ;; }}
      ;;(setq org-latex-default-class "ctexart")
    (add-to-list 'org-latex-packages-alist '("" "minted"))
    (setq org-latex-listings 'minted)
    (setq org-src-fontify-natively t)
    (setq org-latex-pdf-process
            '("xelatex -shell-escape -interaction nonstopmode -output-directory %o %f"
              "xelatex -shell-escape -interaction nonstopmode -output-directory %o %f"
              "xelatex -shell-escape -interaction nonstopmode -output-directory %o %f"
              "xelatex -interaction nonstopmode -output-directory %o %f"
              "xelatex -interaction nonstopmode -output-directory %o %f"
              "xelatex -interaction nonstopmode -output-directory %o %f"
              "rm -fr %b.out %b.log %b.tex auto"))
)

10.3.3 org-latex-instant-preview

(package! org-latex-impatient :recipe (:host github :repo "yangsheng6810/org-latex-impatient"))
(use-package org-latex-impatient
  ;;:hook (org-mode . org-latex-instant-preview-mode)
  :config
  (add-hook 'org-latex-impatient-mode-hook (lambda () (awesome-tab-mode -1)))

  (when IS-LINUX
    (setq org-latex-impatient-tex2svg-bin "/run/current-system/sw/bin/tex2svg")
    (setq org-latex-impatient-scale 10.0)
    )

  (when IS-MAC
    (setq org-latex-impatient-tex2svg-bin
          "~/.nix-profile/bin/tex2svg")
    (setq org-latex-impatient-scale 5.0)
    )
  )

10.4 haskell

10.4.1 lsp-haskell

(package! lsp-haskell)
(use-package! lsp-haskell
  :config
  (setq lsp-haskell-process-path-hie "ghcide")
  (setq lsp-haskell-process-args-hie '())
  (add-hook 'haskell-mode-hook #'lsp)
)

10.5 ccls

(use-package! ccls
  :hook ((c-mode c++-mode objc-mode cuda-mode) .
         (lambda () (require 'ccls) (lsp)))
  )

10.6 Poly && ess

(use-package! polymode)
(use-package! poly-markdown
  :config
  (add-to-list 'auto-mode-alist '("\\.Rmd" . poly-markdown-mode))
  )

10.7 Scheme

(package! geiser)
(use-package! geiser
  :config
  (setq geiser-default-implementation 'racket)
)

10.8 julia

10.8.2 lsp-julia

  • pin “716e7d99a30b26012e5711fb2f33bea71a7bc5ab” to master

    (package! lsp-julia :recipe (:host github :repo "non-Jedi/lsp-julia"))
    
(use-package! lsp-julia
  :config
  ;;(add-hook 'julia-mode-hook #'lsp)
  ;;(setq lsp-julia-default-environment "~/.julia/environments/v1.5")
  (setq lsp-folding-range-limit 100)
)

10.9 python

(package! lsp-pyright)
(setq flycheck-python-pylint-executable "pylint")
(use-package! lsp-pyright
  :config
  (setq lsp-clients-python-command "pyright")
  :hook (python-mode . (lambda ()
                         (require 'lsp-pyright)
                         (lsp))))

10.10 nox

(package! nox :recipe (:host github :repo "manateelazycat/nox"))
(use-package! nox
  :config
  (add-to-list 'nox-server-programs '(haskell-mode . ("ghcide" "--lsp")))
  ;; (dolist (hook (list
  ;;                'js-mode-hook
  ;;                'rust-mode-hook
  ;;                'python-mode-hook
  ;;                'ruby-mode-hook
  ;;                'java-mode-hook
  ;;                'sh-mode-hook
  ;;                'php-mode-hook
  ;;                'c-mode-common-hook
  ;;                'c-mode-hook
  ;;                'c++-mode-hook
  ;;                'haskell-mode-hook
  ;;                ))
  ;;   (add-hook hook '(lambda () (nox-ensure))))
  )

10.12 zeek-mode

(package! zeek-mode :recipe (:host github :repo "ynadji/zeek-mode"))
(use-package! zeek-mode
  :config
  (setq default-tab-width 4)
  (defun add-company-tabnine ()
    (add-to-list (make-local-variable 'company-backends) 'company-tabnine))
  (add-hook 'zeek-mode-hook #'add-company-tabnine)
  )

10.13 nix-mode

(use-package! nix-mode
  :config
  (setq-hook! 'nix-mode-hook company-idle-delay t)
  )

10.14 rust

(setq racer-cmd "racer")
(add-hook 'rustic-mode-hook (lambda () (setq-local +lsp-company-backends '(company-capf))))

11 Visual

11.1 Buffer

11.1.1 Parenthesis

(use-package! rainbow-delimiters
  :config
  (custom-set-faces
   '(rainbow-delimiters-mismatched-face ((t (:foreground "white" :background "red" :weight bold))))
   '(rainbow-delimiters-unmatched-face ((t (:foreground "white" :background "red" :weight bold))))

   ;; show parents (in case of rainbow failing !)
   '(show-paren-match ((t (:foreground "white" :background "green" :weight bold))))
   '(show-paren-mismatch ((t (:foreground "white" :background "red" :weight bold)))))
  (add-hook 'prog-mode-hook #'rainbow-delimiters-mode)
;; highlight brackets
  )

11.1.2 eysbrowse

(package! eyebrowse);
(use-package! eyebrowse
  :config
  (progn
    (define-key eyebrowse-mode-map (kbd "M-1") 'eyebrowse-switch-to-window-config-1)
    (define-key eyebrowse-mode-map (kbd "M-2") 'eyebrowse-switch-to-window-config-2)
    (define-key eyebrowse-mode-map (kbd "M-3") 'eyebrowse-switch-to-window-config-3)
    (define-key eyebrowse-mode-map (kbd "M-4") 'eyebrowse-switch-to-window-config-4)
    (define-key eyebrowse-mode-map (kbd "M-5") 'eyebrowse-switch-to-window-config-5)
    (eyebrowse-mode t)
    (setq eyebrowse-new-workspace t)))

11.2 window

11.2.1 awesome-tab

(use-package! awesome-tab
  :config
  (awesome-tab-mode t)
  (setq awesome-tab-style 'slant)
  ;; winum users can use `winum-select-window-by-number' directly.
  (defun my-select-window-by-number (win-id)
    "Use `ace-window' to select the window by using window index.
WIN-ID : Window index."
    (let ((wnd (nth (- win-id 1) (aw-window-list))))
      (if wnd
          (aw-switch-to-window wnd)
        (message "No such window."))))

  (defun my-select-window ()
    (interactive)
    (let* ((event last-input-event)
           (key (make-vector 1 event))
           (key-desc (key-description key)))
      (my-select-window-by-number
       (string-to-number (car (nreverse (split-string key-desc "-")))))))

  (when (not (display-graphic-p))
    (setq frame-background-mode 'dark))
  (defun awesome-tab-buffer-groups ()
    "`awesome-tab-buffer-groups' control buffers' group rules.

Group awesome-tab with mode if buffer is derived from `eshell-mode' `emacs-lisp-mode' `dired-mode' `org-mode' `magit-mode'.
All buffer name start with * will group to \"Emacs\".
Other buffer group by `awesome-tab-get-group-name' with project name."
    (list
     (cond
      ((or (string-equal "*" (substring (buffer-name) 0 1))
           (memq major-mode '(magit-process-mode
                              magit-status-mode
                              magit-diff-mode
                              magit-log-mode
                              magit-file-mode
                              magit-blob-mode
                              magit-blame-mode
                              )))
       "Emacs")
      ((derived-mode-p 'eshell-mode)
       "EShell")
      ((derived-mode-p 'emacs-lisp-mode)
       "Elisp")
      ((derived-mode-p 'dired-mode)
       "Dired")
      ((memq major-mode '(org-mode org-agenda-mode diary-mode))
       "OrgMode")
      (t
       (awesome-tab-get-group-name (current-buffer))))))

  (defhydra awesome-fast-switch (:hint nil)
    "
 ^^^^Fast Move             ^^^^Tab                    ^^Search            ^^Misc
-^^^^--------------------+-^^^^---------------------+-^^----------------+-^^---------------------------
   ^_k_^   prev group    | _C-a_^^     select first | _b_ search buffer | _C-k_   kill buffer
 _h_   _l_  switch tab   | _C-e_^^     select last  | _g_ search group  | _C-S-k_ kill others in group
   ^_j_^   next group    | _C-j_^^     ace jump     | ^^                | ^^
 ^^0 ~ 9^^ select window | _C-h_/_C-l_ move current | ^^                | ^^
-^^^^--------------------+-^^^^---------------------+-^^----------------+-^^---------------------------
"
    ("h" awesome-tab-backward-tab)
    ("j" awesome-tab-forward-group)
    ("k" awesome-tab-backward-group)
    ("l" awesome-tab-forward-tab)
    ("0" my-select-window)
    ("1" my-select-window)
    ("2" my-select-window)
    ("3" my-select-window)
    ("4" my-select-window)
    ("5" my-select-window)
    ("6" my-select-window)
    ("7" my-select-window)
    ("8" my-select-window)
    ("9" my-select-window)
    ("C-a" awesome-tab-select-beg-tab)
    ("C-e" awesome-tab-select-end-tab)
    ("C-j" awesome-tab-ace-jump)
    ("C-h" awesome-tab-move-current-tab-to-left)
    ("C-l" awesome-tab-move-current-tab-to-right)
    ("b" ivy-switch-buffer)
    ("g" awesome-tab-counsel-switch-group)
    ("C-k" kill-current-buffer)
    ("C-S-k" awesome-tab-kill-other-buffers-in-current-group)
    ("q" nil "quit"))
  )
;; (setq awesome-tab-style "bar")
;; (setq awesome-tab-set-icons t)
;; (setq awesome-tab-set-bar t)
;; (setq awesome-tab-set-bar 'over)
;; (setq awesome-tab-set-modified-marker t)
;; (setq awesome-tab-set-close-button nil)
;; (setq awesome-tab-modified-marker "*")
(global-set-key (kbd "C-c j") 'awesome-tab-forward-tab)
(global-set-key (kbd "C-c k") 'awesome-tab-backward-tab)
(global-set-key (kbd "C-c o") 'awesome-tab-switch-group)

11.2.2 Dimming Unused Windows

(package! dimmer)
(use-package! dimmer
  :config (dimmer-mode))

11.2.3 beacon

(package! beacon)
(use-package! beacon
  :diminish
  :config (setq beacon-color "#666600")
  :hook   ((org-mode text-mode) . beacon-mode))

11.2.4 Flashing when something goes wrong —no blinking

(setq visible-bell 1)

11.2.5 golden-ratio

(use-package! golden-ratio
  :disabled
  :diminish golden-ratio-mode
  :init (golden-ratio-mode 1))

11.3 theme

11.3.1 vbuzin/berrys-theme: A light, clean and elegant Emacs theme

;; (use-package! berrys-theme
;;   :config
;;   (load-theme 'berrys t)

;;   :config ;; for good measure and clarity
;;   (setq-default cursor-type '(bar . 2))
;;   (setq-default line-spacing 2))

11.4 writeroom or writegood

(package! writeroom-mode)
(use-package! writeroom-mode
  :hook
  (org-mode . writeroom-mode)
  (w3m-mode . writeroom-mode)
  :config
  (advice-add 'text-scale-adjust :after
              #'visual-fill-column-adjust)

  ;;https://github.com/joostkremers/writeroom-mode#fullscreen-effect
  (setq writeroom-fullscreen-effect 'maximized)
)
;; (use-package! writegood-mode
;;   ;; Load this whenver I'm composing prose.
;;   ;;:hook (text-mode org-mode)
;;   ;; Don't show me the “Wg” marker in the mode line
;;   :diminish
;;   ;; Some additional weasel words.
;;   :config
;;   (--map (push it writegood-weasel-words)
;;          '("some" "simple" "simply" "easy" "often" "easily" "probably"
;;            "clearly"               ;; Is the premise undeniably true?
;;            "experience shows"      ;; Whose? What kind? How does it do so?
;;            "may have"              ;; It may also have not!
;;            "it turns out that")))  ;; How does it turn out so?
;;            ;; ↯ What is the evidence of highighted phrase? ↯

12 chinese

12.1 pinyinlib

(use-package! pinyinlib
  :config
  (defun re-builder-extended-pattern (str)
    (let* ((len (length str)))
      (cond
       ;; do nothing
       ((<= (length str) 0))

       ;; If the first charater of input in ivy is ":",
       ;; remaining input is converted into Chinese pinyin regex.
       ((string= (substring str 0 1) ":")
        (setq str (pinyinlib-build-regexp-string (substring str 1 len) t)))

       ;; If the first charater of input in ivy is "/",
       ;; remaining input is converted to pattrn to search camel case word
       ((string= (substring str 0 1) "/")
        (let* ((rlt "")
               (i 0)
               (subs (substring str 1 len))
               c)
          (when (> len 2)
            (setq subs (upcase subs))
            (while (< i (length subs))
              (setq c (elt subs i))
              (setq rlt (concat rlt (cond
                                     ((and (< c ?a) (> c ?z) (< c ?A) (> c ?Z))
                                      (format "%c" c))
                                     (t
                                      (concat (if (= i 0) (format "[%c%c]" (+ c 32) c)
                                                (format "%c" c))
                                              "[a-z]+")))))
              (setq i (1+ i))))
          (setq str rlt))))
      (ivy--regex-plus str)))

  (eval-after-load 'ivy
    '(progn
       ;; better performance on everything (especially windows), ivy-0.10.0 required
       ;; @see https://github.com/abo-abo/swiper/issues/1218
       (setq ivy-dynamic-exhibit-delay-ms 250)

       ;; Press C-p and Enter to select current input as candidate
       ;; https://oremacs.com/2017/11/30/ivy-0.10.0/
       (setq ivy-use-selectable-prompt t)

       (setq ivy-re-builders-alist
             '((t . re-builder-extended-pattern)))
       ;; set actions when running C-x b
       ;; replace "frame" with window to open in new window
       (ivy-set-actions
        'ivy-switch-buffer-by-pinyin
        '(("j" switch-to-buffer-other-frame "other frame")
          ("k" kill-buffer "kill")
          ("r" ivy--rename-buffer-action "rename")))))
  (with-eval-after-load "swiper-isearch"
    (setq ivy-re-builders-alist
          '((t . re-builder-extended-pattern)
            (t . ivy-prescient-re-builder))))
  )

12.2 helm-pinyin

;; (package! helm-pinyin :recipe (:host github :repo "twlz0ne/helm-pinyin"))
;; (use-package! helm-pinyin
;;   :hook
;;   (after-init . turn-on-helm-pinyin)
;;   )

13 minor mode and major mode

14 Writing

14.1 grammarly

;;(package! flycheck-grammarly :recipe (:host github :repo "jcs-elpa/flycheck-grammarly"))
(package! company-english-helper :recipe (:host github :repo "manateelazycat/company-english-helper"))
(package! emacs-powerthesaurus :recipe (:host github :repo "SavchenkoValeriy/emacs-powerthesaurus"))
(use-package! company-english-helper)
;;(use-package! flycheck-grammarly)

15 load & unload

15.1 disbale-package

(disable-packages! pyim)
(disable-packages! company-go)
(disable-packages! lsp-python-ms)

16 misc

17 set popup rules

;; (custom-set-faces
;;   '(awesome-tab-close-selected((t ( :foreground "DarkGray"))))
;;   )

(set-popup-rule! "^\\*org-graph-view" :side 'right :size 70 :quit nil :select t :ttl 0)

(set-popup-rule! "^\\*julia:main"
  :side 'right :size 0.3 :quit nil :select nil :ttl 0)

(set-popup-rule! "^\\*Ilist"
  :side 'right :size 35 :quit nil :select nil :ttl 0)

(after! org
  (set-popup-rule! "^\\*Org tags" :size 0.5))

(after! helm
  (set-popup-rule! "^\\*helm" :size 0.5))

(after! maple-explorer-imenu
(set-popup-rule! "^\\*maple-explorer-imenu"
  :side 'right :size 35 :quit nil :select nil :ttl 0)
)

18 Linux & Macsos

(load! "./modules/my-linux.el")
(load! "./modules/my-macos.el")

18.1 Linux only

(use-package! my-linux
  :load-path "./modules"
  :if (eq system-type 'gnu/linux)
  :config
  ;;(add-hook! 'emacs-startup-hook 'doom-modeline-mode)
  ;;fix post hook only linux
  (require 'savehist)
  (setq-default cursor-type 'box)
  (blink-cursor-mode -1)
  (set-cursor-color "IndianRed3")
  (setq bm-repository-file (f-join doom-private-dir "etc/bm-linux-data"))
  (setq bookmark-default-file
        (concat doom-private-dir "etc/bookmark-linux-default.el"))


  (setq python-shell-interpreter "python")
  (setq eaf-python-command "python")

  (bookmark-load bookmark-default-file t)

  (setq org-roam-db-location "~/.emacs.d/.local/cache/org-roam.db")

  (when (not window-system)
    (xterm-mouse-mode 1)
    )
  (setq org-crypt-key "24945FE0DBD04F4C045025F96F92B3E8F942D425")

  (set-face-attribute
   'default nil
   :font (font-spec :name "-PfEd-Fantasque Sans Mono-bold-italic-normal-*-*-*-*-*-m-0-iso10646-1"
                    :weight 'normal
                    :slant 'normal
                    :size 12.0))

  (when (display-graphic-p)
    (dolist (charset '(kana han cjk-misc bopomofo))
      (set-fontset-font (frame-parameter nil 'font) charset
                        (font-spec :family "Weibei SC" :size 55)))
    )

  (define-key org-mode-map (kbd "C-c l") 'grab-x-link)

  (setq inferior-julia-program-name "/run/current-system/sw/bin/julia")
  ;; (setq jupyter-runtime-directory "~/.local/share/jupyter/runtime")
  (add-hook 'ob-async-pre-execute-src-block-hook
            '(lambda ()
               (setq inferior-julia-program-name "/run/current-system/sw/bin/julia")))
  )

18.1.1 eaf

(when IS-LINUX
  (package! eaf :recipe (:host github
                            :repo "manateelazycat/emacs-application-framework"
                            :files ("*")
                            :no-byte-compile t))
  )
(when (display-graphic-p)
  (use-package! eaf
    :if (eq system-type 'gnu/linux)
    :custom
    (eaf-find-alternate-file-in-dired t)
    :config
    (add-hook! 'eaf-mode-hook 'xah-fly-keys-off)

    (eaf-bind-key scroll_up "C-n" eaf-pdf-viewer-keybinding)
    (eaf-bind-key scroll_down "C-p" eaf-pdf-viewer-keybinding)

    (defun eaf-open-google ()
      "Open Google using EAF."
      (interactive)
      (eaf-open-browser "https://www.google.com")))
  )

18.1.2 grab-x-link   nix

(use-package! grab-x-link
  :if (eq system-type 'gnu/linux)
  )

18.2 my-linux

;;; my-linux.el -*- lexical-binding: t; -*-
(provide 'my-linux)

18.3 my MacOS setting

(use-package! my-macos
:load-path "./modules"
:if (memq window-system '(mac ns))
:config
 (setq bookmark-default-file
        (concat doom-private-dir "etc/bookmark-macos-default.el"))
 (bookmark-load bookmark-default-file t)

(setq-default cursor-type 'box)
(blink-cursor-mode -1)
(set-cursor-color "yellow1")
(setq bm-repository-file (f-join doom-private-dir "etc/bm-macos-data"))
(setq insert-directory-program "/usr/local/bin/gls")

(setq org-roam-db-location "~/.emacs.d/.local/cache/org-roam-macos.db")

(define-key org-mode-map (kbd "C-c l") 'org-mac-grab-link)
;;(eval-after-load 'tramp '(setenv "SHELL" "/bin/bash"))

(set-face-attribute
 'default nil
 :font (font-spec :name "-*-Fantasque Sans Mono-normal-normal-normal-*-*-*-*-*-m-0-iso10646-1"
                  :weight 'normal
                  :slant 'normal
                  :size 25.0))
(dolist (charset '(kana han symbol cjk-misc bopomofo))
  (set-fontset-font
   (frame-parameter nil 'font)
   charset
   (font-spec :name "-*-STFangsong-normal-normal-normal-*-*-*-*-*-p-0-iso10646-1"
              :weight 'normal
              :slant 'normal
              :size 24.5)))

(setq ispell-program-name "~/.nix-profile/bin/ispell")

;; (setq lsp-python-ms-executable
;;       "~/src/python-language-server/output/bin/Release/osx-x64/publish/Microsoft.Python.LanguageServer")

(setq inferior-julia-program-name "/usr/local/bin/julia")

(add-hook 'ob-async-pre-execute-src-block-hook
        '(lambda ()
           (setq inferior-julia-program-name "/usr/local/bin/julia")))
;;(add-hook! 'emacs-startup-hook 'doom-modeline-mode)
)

18.4 macos use packages

(package! cnfonts)
(package! exec-path-from-shell)
;;; my-macos.el -*- lexical-binding: t; -*-
(use-package! cnfonts)
(use-package! exec-path-from-shell)
(define-key! awesome-tab-mode-map
  "s-1" #'awesome-tab-select-visible-tab
  "s-2" #'awesome-tab-select-visible-tab
  "s-3" #'awesome-tab-select-visible-tab
  "s-4" #'awesome-tab-select-visible-tab
  "s-5" #'awesome-tab-select-visible-tab
  "s-6" #'awesome-tab-select-visible-tab
  "s-7" #'awesome-tab-select-visible-tab
  "s-8" #'awesome-tab-select-visible-tab
  "s-9" #'awesome-tab-select-visible-tab
  )
(provide 'my-macos)

19 Bugs

19.1 <2020-10-13 Tue> magit commit server error

with-editor

  rm -rf ~/.emacs.d/.local/straight/repos/with-editor
  rm -rf ~/.emacs.d/.local/straight/build/with-editor

rebuild

20 r0man/docopt.el: A Docopt implementation in Emacs Lisp.

21 Cache

Date: 2019-12-30 Mon

Created: 2021-01-08 Fri 22:10

Emacs 28.0.50 (Org mode 9.5)