My Doom Emacs config

Table of Contents

HTML them READ org

1 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/

(doom! :input

       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

       ;;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
       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
       ;;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

       ;;(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

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

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

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

       ;;debugger          ; FIXME stepping through code, to help you add bugs
       ;;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
       ;;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

       ;;agda              ; types of types of types of types...
       ;;assembly          ; assembly for fun or debugging
       cc                ; 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

       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
       ;;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
        ;+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
        +lsp)            ; 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

       ;;(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.
       ;;irc               ; how neckbeards socialize
       (rss +org)        ; emacs as an RSS reader
       ;;twitter           ; twitter client
       ;;(write            ; emacs for writers (fiction, notes, papers, etc.)
       ;; +wordnut         ; wordnet (wn) search
       ;; +langtool)       ; a proofreader (grammar/style check) for Emacs

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

       ;; 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)

2 package.el

(package! bm)
(package! w3m)
(package! discover :recipe (:host github :repo "mickeynp/discover.el"))
(package! xah-fly-keys :recipe (:host github :repo "xahlee/xah-fly-keys"))
(package! hungry-delete)
(package! flymake-json)
(package! maple-iedit :recipe (:host github :repo "honmaple/emacs-maple-iedit"))
(package! yatemplate)
(package! pinyin-search)
(package! grab-x-link)
(package! ctrlf :recipe (:host github :repo "raxod502/ctrlf"))

;; window
(package! dimmer)
(package! beacon)
(package! golden-ratio)
(package! writegood-mode)

2.1 third-part

(package! eyebrowse)
(package! cnfonts)
(package! scrollkeeper :recipe (:host github :repo "alphapapa/scrollkeeper.el"))
(package! elfeed-goodies)
(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! imenu-list)
(package! helm-tramp)
(package! visual-fill-column)
(package! wakatime-mode)
(package! sunrise-commander :recipe (:host github :repo "sunrise-commander/sunrise-commander"))
;; (package! berrys-theme)

3 config.el

(load! "setting")
(load! "xah-fly.el")

(use-package! ctrlf
  (after-init . ctrlf-mode))
;;[2020-03-26 Thu 16:39]
(use-package! wakatime-mode
:hook (after-init . global-wakatime-mode))
(use-package! pinyin-search)

(use-package! helm-tramp
  (setq tramp-default-method "ssh")
  (setq make-backup-files nil)
  (setq create-lockfiles nil)
  (setq helm-tramp-custom-connections '(/ssh:gtrun@ /ssh: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)

3.1 default

(setq user-full-name "GTrunSec"
      user-mail-address "")
(setq-default history-length 1000)
(setq create-lockfiles nil)
;; (setq browse-url-browser-function 'browse-url-Chrome)
(setq dired-dwim-target t)
(add-hook! 'xah-fly-command-mode-activate-hook 'xah-fly-save-buffer-if-file)
;;(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)
(add-hook! 'elfeed-show-mode-hook 'gtrun/truncate-lines-hook)
(add-hook! 'sunrise-start-hook 'xah-fly-insert-mode-activate)
(add-hook 'maple-explorer-imenu-mode-hook
          (lambda() (setq cursor-type 'box
                          cursor-in-non-selected-windows t)))

(setenv "XAPIAN_CJK_NGRAM" "1")

(setq w3m-use-tab-line nil)

4 autoload

4.1 misc

4.1.1 time

;;; ~/.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")

(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."
       ;;(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")

(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."
       ;;(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")

(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."
       ;;(insert "==========\n")
;       (insert (let () (comment-start)))
       (insert (format-time-string current-date-time-format-active (current-time)))
       ;;(insert "\n")

4.1.2 default

;;; ~/.doom.d/autoload/+default.el -*- lexical-binding: t; -*-

5 org-mode

5.1 config

(load! "setting")
(add-hook! 'after-init-hook 'org-starter-load-all-files-in-path)
(add-hook! 'org-mode-hook 'auto-revert-mode)
(use-package! company-english-helper)
(use-package! ox-hugo)
(use-package! ob-session-async)
(use-package! ob-async)
(use-package! org-books
(setq org-books-file "~/Documents/org-notes/GTD/")
;;(use-package emacs-powerthesaurus)

5.2 Packages

(package! company-english-helper :recipe (:host github :repo "manateelazycat/company-english-helper"))
(package! org-super-agenda)
(package! ob-mermaid)
(package! org-starter)
(package! helm-org-rifle)
(package! org-wild-notifier)
(package! org-books :recipe (:host github :repo "lepisma/org-books"))
;;(package! deft)
(package! notdeft :recipe (:host github :repo "hasu/notdeft"))
(package! emacs-powerthesaurus :recipe (:host github :repo "SavchenkoValeriy/emacs-powerthesaurus"))

5.3 setting

5.3.1 org-global

(setq org-clock-into-drawer t)
(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)
(setq org-download-timestamp "%Y%m%d_%H%M%S")

5.3.2 org-babel

;; Todo part

(setq ein:output-type-preference
      '(emacs-lisp svg png jpeg html text latex javascript))

(defun my-org-confirm-babel-evaluate (lang _body)
  "Return t if LANG is in whitelist."
  (not (or (string= lang "ditaa")
           (string= lang "dot")
           (string= lang "R")
           (string= lang "julia")
           (string= lang "C++")
           (string= lang "C")
           (string= lang "ein-R")
           (string= lang "python")
           (string= lang "ein-julia")
           (string= lang "ein-python")
           (string= lang "plantuml"))))
(setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)

(setq org-bullets-bullet-list '("☰" "☷" "☵" "☲"  "☳" "☴"  "☶"  "☱" ))

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

5.3.3 agenda-custom-setting

(setq org-agenda-custom-commands
      '(("z" "GtruN Agenda"
         ((agenda "" ((org-agenda-span 2)
                      (org-agenda-start-day "-1d")
                       '((:name "Today List"
                                :time-grid t
                                :date today
                                :todo "⚔ INPROCESS"
                                :scheduled today
                                :order 1)))))
          (alltodo "" ((org-agenda-overriding-header "")
                        '((: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-}")
         search "+{^\\*+\\s-+\\(⚔ INPROCESS\\)\\s-}")


5.3.4 org-key

(eval-after-load "org"
  '(require 'ox-md nil t))
(define-key! org-mode-map (kbd "C-<return>") 'org-insert-heading-respect-content)

5.3.5 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=\"\">%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=\"\">%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)

5.4 org-wild-notifier

(use-package! org-wild-notifier
  :defer t
  (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)))

5.5 super-agenda

(use-package! org-super-agenda
  (add-hook! 'after-init-hook 'org-super-agenda-mode)
  (require 'org-habit)
  ;; (setq org-agenda-time-grid
  ;;       '((daily today)
  ;;         ))
   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)

5.6 org-starter

(use-package org-starter
  ;; (add-hook! 'after-init-hook 'org-starter-load-all-files-in-path)
  (org-starter-def "~/Documents/org-notes"
                   ("GTD/"                      :agenda t :key "g" :refile (:maxlevel . 5))
                   ("GTD/"                    :agenda t :key "n" :refile (:maxlevel .5 ))
                   ("GTD/"                   :agenda t :key "m" :refile (:maxlevel .5 ))
                   ("GTD/"                    :agenda t :key "h" :refile (:maxlevel .5 ))
                   ("post/traveling/" :key "t" :refile (:maxlevel .5 ))
                   ("post/myself/"         :key "l" :refile (:maxlevel .5 ))
                   ("post/myself/"         :key "q" :refile (:maxlevel .5 ))
                   ("post/myself/"         :key "p" :refile (:maxlevel .5 ))
                   ("GTD/"             :agenda t :key "b" :refile (:maxlevel .5 ))
                   ("NSM-GTD/"         :agenda t :required t)
                   ("NSM-GTD/"           :agenda t :required t)
                   ("art/"                :agenda t :required t)
  (org-starter-def "~/.config/nixpkgs/dotfiles/doom/"
                   ("" :key "i" :refile (:maxlevel . 5))
                   ;;("" :key "x" :refile (:maxlevel . 5))
  (org-starter-def "~/.config/nixpkgs"
                   ("dotfiles/wallpaper/" :agenda nil)

 (defhydra gtrun/hydra-org-starter nil
 _i_:    _g_:      _l_:
 _n_: note        _t_: traveling    _h_:
 _m_: myself      _q_: 情-qing      _p_:
 _b_: my-books

      ("i" org-starter-find-file:init)
      ("g" org-starter-find-file:gtd)
      ("n" org-starter-find-file:notes)
      ("m" org-starter-find-file:myself)
      ("t" org-starter-find-file:traveling)
      ("q" org-starter-find-file:qing)
      ("l" org-starter-find-file:love)
      ("h" org-starter-find-file:Habit)
      ("p" org-starter-find-file:plan)
      ("b" org-starter-find-file:my-books)
  ("C-c e" . org-starter-select-file))
 ;; "C-c e" . org-starter-refile-by-key))


5.7 elfeed

(use-package! elfeed
  :bind (:map elfeed-search-mode-map
          ("q" . bjm/elfeed-save-db-and-bury)
          ("Q" . bjm/elfeed-save-db-and-bury)
          ("m" . elfeed-toggle-star)
(global-set-key (kbd "C-x w") 'elfeed)
(setf url-queue-timeout 30)
(setq elfeed-db-directory "~/Dropbox/shared/elfeeddb")
;;functions to support syncing .elfeed between machines
;;makes sure elfeed reads index from disk before launching
(defun bjm/elfeed-load-db-and-open ()
  "Wrapper to load the elfeed db from disk before opening"

;;write to disk when quiting

(defun bjm/elfeed-save-db-and-bury ()
  "Wrapper to save the elfeed db to disk before burying buffer"

(defun elfeed-mark-all-as-read ()


(use-package! elfeed-goodies

(use-package! elfeed-org
(setq rmh-elfeed-org-files (list "~/Documents/org-notes/")))
(use-package! helm-org-rifle)

5.8 org publish

  (setq org-publish-project-alist
           :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 ""
           :base-directory "~/Documents/org-publish"
           :publishing-function org-html-publish-to-html
           :publishing-directory "~/Documents/my-blog/public/custom"
           :exclude ""
           :base-directory "~/.config/nixpkgs/dotfiles/doom"
           :publishing-function org-html-publish-to-html
           :publishing-directory "~/Documents/my-blog/public/custom"
           :base-directory "~/Dropbox/Drop-project/my-mathematic-env/math"
           :publishing-function org-html-publish-to-html
           :publishing-directory "~/Documents/my-blog/public/custom"
           :base-directory "~/Documents/org-notes/art"
           :publishing-function org-html-publish-to-html
           :publishing-directory "~/Documents/my-blog/public/custom"
           :base-directory "~/Documents/org-notes/course"
           :publishing-function org-html-publish-to-html
           :publishing-directory "~/Documents/my-blog/public/custom"

5.9 org-notdeft

(use-package! notdeft
  (setq notdeft-extension "org")
  ;;(setq notdeft-secondary-extensions '("md" "org" "scrbl"))
  (setq notdeft-directories '("~/Documents/org-notes/post/myself"

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

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

5.11 org-export

5.11.1 highlight

  ;; (require 'ox)
  ;; (defun my-html-mark-tag (text backend info)
  ;;   "Transcode :blah: into <mark>blah</mark> in body text."
  ;;   (when (org-export-derived-backend-p backend 'html)
  ;;     (let ((text (replace-regexp-in-string "[^\\w]\\(:\\)[^\n\t\r]+\\(:\\)[^\\w]" "<mark>"  text nil nil 1 nil)))
  ;;       (replace-regexp-in-string "[^\\w]\\(<mark>\\)[^\n\t\r]+\\(:\\)[^\\w]" "</mark>" text nil nil 2 nil))))

  ;; (add-to-list 'org-export-filter-plain-text-functions 'my-html-mark-tag)

  ;; (defun my-html-mark-tag (text backend info)
  ;;   "Transcode :blah: into <mark>blah</mark> in body text."
  ;;   (when (org-export-derived-backend-p backend 'html)
  ;;     (let ((text (replace-regexp-in-string "[^\\w]\\(:\\)[^\n\t\r]+\\(:\\)[^\\w]" "<mark>"  text nil nil 1 nil)))
  ;;       (replace-regexp-in-string "[^\\w]\\(<mark>\\)[^\n\t\r]+\\(:\\)[^\\w]" "</mark>" text nil nil 2 nil))))

  ;; (add-to-list 'org-export-filter-plain-text-functions 'my-html-mark-tag)

5.12 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)

5.18 ob-mermaid

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

5.19 dustinlacewell/org-spacer.el: Enforce the number of blank lines between elements in an org-mode document

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

5.20 mtekman/org-density.el: Examine the density of org headings

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

6 Completion

6.1 Ivy/counsel

  (use-package! counsel
    (after-init . ivy-mode)
    (counsel-grep-post-action . better-jumper-set-jump)
    :diminish ivy-mode
    (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
       (ivy-rich-mode 1)
       (setq ivy-format-function #'ivy-format-function-line))
     ;;[[][gilbertw1/better-jumper: A configurable jump list implementation for Emacs]]

6.2 company

(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."
  (let* ((k (this-command-keys))
         (re (concat "^" company-prefix k)))
    (if (or (cl-find-if (lambda (s) (string-match re s))
            (> (string-to-number k)
               (length company-candidates))
            (looking-back "[0-9]+\\.[0-9]*" (line-beginning-position)))
        (self-insert-command 1)
       (if (equal k "0")
         (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 ()
                        (self-insert-command 1)))
  (define-key map (kbd "<return>") nil))

6.3 company-backend

(set-company-backend! '(nix-mode)
  '(:separate company-nixos-options

;;  (set-company-backend! 'sh-mode nil) ; unsets backends for sh-mode
(set-company-backend! '(org-mode)
  '(:separate company-english-helper-search
(set-company-backend! '(c-mode
  '(:separate company-tabnine

(setq +lsp-company-backend '(company-lsp :with company-tabnine :separate))

6.4 company-tabnine

(use-package! company-tabnine
  :when (featurep! :completion company)
  (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.
  (setq company-frontends


6.5 Edition

6.5.1 Maple

  (use-package! maple-iedit
    :commands (maple-iedit-match-all maple-iedit-match-next maple-iedit-match-previous)
    (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)
                ("C-," . maple-iedit-skip-and-match-next)
                ("C-." . maple-iedit-skip-and-match-previous)

6.5.2 awesome-pair

(use-package! awesome-pair)

6.6 Bookmark

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

     :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."

    (advice-add 'bm-bookmark-add
                :after (lambda (&rest args)
    (advice-add 'bm-bookmark-remove
                :after (lambda (&rest args)
    (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 ()

    (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)))
                   (insert-file-contents-literally (car entry))
                   (cl-letf (((symbol-function 'bm-bookmark-add)
                              (lambda (&optional annotation time temporary)
                                (!cons (list (car entry)
                                             (string-trim (thing-at-point 'line t)))
                             ((symbol-function 'message)
                              (lambda (&rest _))))
                     (bm-buffer-restore-2 (cdr entry)))))

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

      (defvar adq/helm-bm-all-source
        (helm-build-sync-source "Helm All Bookmarks"
          (lambda ()
            (mapcar #'adq/helm-bm-all-format-bookmark
          '(("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."
        (helm :sources 'adq/helm-bm-all-source
              :buffer "*helm bm all*"))

    (defhydra adq/hydra-bm nil
  _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))

6.7 templating

(use-package! yatemplate
  :after yasnippet

  ;; Define template directory
  (setq yatemplate-dir (concat doom-private-dir "modules/templates"))

  ;; Coupling with auto-insert
  (setq auto-insert-alist nil)
  (add-hook 'find-file-hook 'auto-insert)

6.8 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)

6.10 maple-imenu

(use-package! maple-explorer
  :commands (maple-explorer-file maple-explorer-buffer maple-explorer-imenu maple-explorer-recentf)
  (setq maple-explorer-file-display-alist '((side . left) (slot . -1)))

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

7 format

7.1 html file to ox-hugo

  ;; (require 'ox)
  ;; (defun my-html-ox-hugo (text backend info)
  ;;   "Transcode :blah: into <mark>blah</mark> in body text."
  ;;   (when (org-export-derived-backend-p backend 'html)
  ;;     (let ((text (replace-regexp-in-string "file" "/ox-hugo/"  text nil nil 1 nil))))))

  ;; (add-to-list 'org-export-filter-plain-text-functions 'my-html-ox-hugo)

8 minor mode and major mode

9 Writing

9.1 grammarly

;;(package! flycheck-grammarly :recipe (:host github :repo "jcs-elpa/flycheck-grammarly"))
;;(use-package! flycheck-grammarly)

10 Visual

10.1 Buffer

10.1.1 Parenthesis

(use-package! rainbow-delimiters
   '(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
(setq show-paren-style 'parenthesis)

10.1.2 eysbrowse

(use-package! eyebrowse
    (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)))

10.2 window

10.2.1 setting

(add-hook 'visual-line-mode-hook #'visual-fill-column-mode)
(add-hook 'visual-fill-column-mode-hook #'visual-line-mode)
(add-hook 'w3m-display-hook #'visual-line-mode)
(add-hook! 'after-init-hook #'global-hungry-delete-mode)
(add-hook! 'after-init-hook #'cua-mode)
(add-hook 'before-save-hook 'whitespace-cleanup)

(advice-add 'text-scale-adjust :after

10.2.2 tab

(use-package! awesome-tab
(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 ()
  (let* ((event last-input-event)
         (key (make-vector 1 event))
         (key-desc (key-description key)))
     (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."
    ((or (string-equal "*" (substring (buffer-name) 0 1))
         (memq major-mode '(magit-process-mode
    ((derived-mode-p 'eshell-mode)
    ((derived-mode-p 'emacs-lisp-mode)
    ((derived-mode-p 'dired-mode)
    ((memq major-mode '(org-mode org-agenda-mode diary-mode))
     (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)

10.2.3 Dimming Unused Windows

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

10.2.4 beacon

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

10.2.5 Flashing when something goes wrong —no blinking

(setq visible-bell 1)

10.2.6 golden-ratio

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

10.3 theme

10.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))

10.4 [[][bnbeckwith/writegood-mode: Minor mode for Emacs to improve English writing


(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
  ;; Some additional weasel words.
  (--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? ↯

11 git

12 my-codes

12.1 packages

(package! awesome-pair :recipe (:host github :repo "manateelazycat/awesome-pair"))
(package! lsp-julia :recipe (:host github :repo "gdkrmr/lsp-julia"))
(package! plantuml-mode)
(package! ccls)
(package! company-tabnine)
(package! polymode)
(package! poly-markdown)
(package! lsp-haskell)
(package! bicycle)
(package! jsonrpc)
(load! "my-latex")
(load! "show-parentheses")

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

(use-package! lsp-mode
 ;; Support LSP in Org Babel with header argument `:file'.
  (defvar org-babel-lsp-explicit-lang-list
    "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)))))
         (defun ,intern-pre (info)
           (let ((lsp-file (or (->> info caddr (alist-get :file))
                               (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))
         (if (fboundp ',edit-pre)
             (advice-add ',edit-pre :after ',intern-pre)
             (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
      ;; "ruby"
      "js" "css"
      ;; "C" "C++"

      "rust" "go" "java"))

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

12.2 ccls

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

12.3 Poly

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

12.4 Latex

12.4.1 auctex

 ;; (use-package! auctex)

12.4.2 chinese-latex

(after! latex
      (add-to-list 'org-latex-classes '("article" "\\documentclass[a4paper,11pt]{article}

          \\setCJKmainfont{Weibei SC}
          \\setmainfont{Fantasque Sans Mono}
                                        ("\\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
      ;; 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"))

12.5 Scheme

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

12.6 Code misc

12.6.1 parentheses

;;; -*- lexical-binding: t; -*-

;; we will call `blink-matching-open` ourselves...

(remove-hook 'post-self-insert-hook
;; 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
    (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
                 (and (not (bobp))
                      (memq (char-syntax (char-before)) '(?\) ?\$)))
                 (= 1 (logand 1 (- (point)
                                     (forward-char -1)
                                     (skip-syntax-backward "/\\")
        ;; 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 ))))))

(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)
    (overlay-put ol 'display str)
    (overlay-put ol 'face
                 (or face '(:inherit default :inherit highlight)))

(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)

12.7 julia

12.7.2 lsp-julia

(use-package! lsp-julia
  (add-hook 'julia-mode-hook #'lsp)
  (setq lsp-julia-default-environment "~/.julia/environments/v1.3")
  (setq lsp-folding-range-limit 100)
  (setq lsp-julia-package-dir nil)
  (setq lsp-julia-flags '("--project=/Users/gtrun/.julia/packages/languageserver"  "--startup-file=no" "--history-file=no"))

12.8 nox

(package! nox :recipe (:host github :repo "manateelazycat/nox"))
(use-package! nox
  ;; (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))))

12.9 python

(setq flycheck-python-pylint-executable "pylint")

13 chinese

13.1 pinyinlib

(use-package! pinyinlib

  (defun re-builder-extended-pattern (str)
    (let* ((len (length str)))
       ;; 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))
          (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))
                                      (concat (if (= i 0) (format "[%c%c]" (+ c 32) c)
                                                (format "%c" c))
              (setq i (1+ i))))
          (setq str rlt))))
      (ivy--regex-plus str)))

  (eval-after-load 'ivy
       ;; better performance on everything (especially windows), ivy-0.10.0 required
       ;; @see
       (setq ivy-dynamic-exhibit-delay-ms 250)

       ;; Press C-p and Enter to select current input as candidate
       (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
        '(("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))))

14 load & unload

14.1 after-init

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

15 set face

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

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

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

16 Linux & Macsos

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

16.1 Linux

(use-package! my-linux
  :load-path "./modules"
  :if (eq system-type 'gnu/linux)
  (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"))

  (bookmark-load bookmark-default-file t)

  (setq lsp-python-ms-executable  "~/.nix-profile/bin/mspyls")
  (when (not window-system)
    (xterm-mouse-mode 1)
  (setq org-crypt-key "24945FE0DBD04F4C045025F96F92B3E8F942D425")
   '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 notdeft-xapian-program "/home/gtrun/src/notdeft/xapian/notdeft-xapian")
  ;; (setq jupyter-runtime-directory "~/.local/share/jupyter/runtime")

  (add-hook 'ob-async-pre-execute-src-block-hook
            '(lambda ()
               (setq inferior-julia-program-name "/nix/store/fi7c1417hcv093ffyf03rdrlw84qb6mi-system-path/bin/julia")))


(use-package! grab-x-link
  :if (eq system-type 'gnu/linux)
(when (display-graphic-p)
  (use-package! eaf
    :if (eq system-type 'gnu/linux)
    :load-path "~/.myscript/eaf"
    (eaf-find-alternate-file-in-dired t)
    (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."
      (eaf-open-browser "")))

(use-package! snails
  :if (eq system-type 'gnu/linux)
  :load-path "~/.myscript/snails"
  (define-key snails-mode-map [remap next-line] #'snails-select-next-item)
  (add-hook 'snails-mode-hook #'xah-fly-insert-mode-activate))
(provide 'my-linux)

16.2 MacOS

(use-package! my-macos
:load-path "./modules"
:if (memq window-system '(mac ns))
 (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")
(define-key org-mode-map (kbd "C-c l") 'org-mac-grab-link)
;;(eval-after-load 'tramp '(setenv "SHELL" "/bin/bash"))

 '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))
   (frame-parameter nil 'font)
   (font-spec :name "-*-STFangsong-normal-normal-normal-*-*-*-*-*-p-0-iso10646-1"
              :weight 'normal
              :slant 'normal
              :size 24.5)))

(setq ispell-program-name "/usr/local/bin/ispell")

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

(setq notdeft-xapian-program "/Users/gtrun/src/notdeft/xapian/notdeft-xapian")

(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)


16.2.1 macos-setting

(use-package! cnfonts)

(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)

17 Cache

Date: 25 October 2019

Created: 2020-04-07 Tue 20:32

Emacs 26.3 (Org mode 9.4)