:PROPERTIES:
:ID:       d73010f8-e75a-4163-b09e-46f9df39bc53
:END:
#+title: GuangTao's Doom Emacs Config
#+email: gtrunsec@hardenedlinux.org
#+author: GuangTao Zhang
#+header-args:emacs-lisp: :dir ~/.doom.d

* init.el
:PROPERTIES:
:ID:       4f9d417d-66b2-457e-9cf2-9b53f23d6aa1
:END:

** default
#+begin_src emacs-lisp :tangle "init.el"
;;; init.el -*- lexical-binding: t; -*-
(doom! :input
       ;;bidi              ; (tfel ot) thgir etirw uoy gnipleh
       chinese
       ;;japanese
       ;;layout            ; auie,ctsrnm is the superior home row

       :completion
       ;; (company           ; the ultimate code completion backend
       ;;  +auto
       ;;  +childframe)
       ;;helm              ; the *other* search engine for love and life
       ;;ido               ; the other *other* search engine...
       ;;ivy               ; a search engine for love and life
       ;; (ivy
       ;;  +childframe)
       vertico           ; the search engine of the future

       :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
       ;;(emoji +unicode)  ; 🙂
       hl-todo           ; highlight TODO/FIXME/NOTE/DEPRECATED/HACK/REVIEW
       ;;hydra
       ;;indent-guides     ; highlighted indent columns
       ;;ligatures         ; ligatures and symbols to make your code pretty again
       ;;minimap           ; show a map of the code on the side
       modeline          ; snazzy, Atom-inspired modeline, plus API
       nav-flash         ; blink cursor line after big motions
       ;;neotree           ; a project drawer, like NERDTree for vim
       ophints           ; highlight the region an operation acts on
       (popup +defaults)   ; tame sudden yet inevitable temporary windows
       ;;tabs              ; a tab bar for Emacs
       treemacs          ; a project drawer, like neotree but cooler
       ;;unicode           ; extended unicode support for various languages
       (vc-gutter +pretty) ; 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
       zen               ; distraction-free coding or writing

       :editor
       ;;(evil +everywhere); come to the dark side, we have cookies
       file-templates    ; auto-snippets for empty files
       fold              ; (nigh) universal code folding
       ;;(format +onsave)  ; automated prettiness
       ;;god               ; run Emacs commands without modifier keys
       ;;lispy             ; vim for lisp, for people who don't 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]
       ;;  +dirvish)
       electric          ; smarter, keyword-based electric-indent
       ;;ibuffer         ; interactive buffer management
       undo              ; persistent, smarter undo for your inevitable mistakes
       vc                ; version-control and Emacs, sitting in a tree

       :term
       ;;eshell            ; the elisp shell that works everywhere
       ;;shell             ; simple shell REPL for Emacs
       ;;term              ; basic terminal emulator for Emacs
       vterm             ; the best terminal emulation in Emacs

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

       :tools
       direnv
       ;;ansible
       ;;biblio            ; Writes a PhD for you (citation needed)
       ;;debugger          ; FIXME stepping through code, to help you add bugs
       ;;docker
       ;;editorconfig      ; let someone else argue about tabs vs spaces
       ;;ein               ; tame Jupyter notebooks with emacs
       ;;(eval +overlay)     ; run code, run (also, repls)
       ;;gist              ; interacting with github gists
       lookup              ; navigate your code and its documentation
       ;;lsp               ; M-x vscode
       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
       ;;taskrunner        ; taskrunner for all your projects
       terraform         ; infrastructure as code
       ;;tmux              ; an API for interacting with tmux
       tree-sitter       ; syntax and parsing, sitting in a tree...
       ;;upload            ; map local to remote projects via ssh/ftp

       :os
       (:if IS-MAC macos)  ; improve compatibility with macOS
       ;;tty               ; improve the terminal Emacs experience

       :lang
       ;;agda              ; types of types of types of types...
       ;;beancount         ; mind the GAAP
       ;;(cc +lsp)         ; C > C++ == 1
       ;;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
       ;;(dart +flutter)   ; paint ui and not much else
       ;;dhall
       ;;elixir            ; erlang done right
       ;;elm               ; care for a cup of TEA?
       emacs-lisp        ; drown in parentheses
       ;;erlang            ; an elegant language for a more civilized age
       ;;ess               ; emacs speaks statistics
       ;;factor
       ;;faust             ; dsp, but you get to keep your soul
       ;;fortran           ; in FORTRAN, GOD is REAL (unless declared INTEGER)
       ;;fsharp            ; ML stands for Microsoft's Language
       ;;fstar             ; (dependent) types and (monadic) effects and Z3
       ;;gdscript          ; the language you waited for
       go;;(go +lsp)         ; the hipster dialect
       ;;(graphql +lsp)    ; Give queries a REST
       haskell;;(haskell +lsp)    ; a language that's lazier than I am
       ;;hy                ; readability of scheme w/ speed of python
       ;;idris             ; a language you can depend on
       json              ; At least it ain't XML
       ;;(java +lsp)       ; 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              ; for folks with too much to prove
       ;;ledger            ; be audit you can be
       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
        +jupyter
        +dragndrop
        +roam2)
       ;;php               ; perl's insecure younger brother
       ;;plantuml          ; diagrams for confusing people more
       ;;purescript        ; javascript, but functional
       python            ; beautiful is better than ugly
       ;;qt                ; the 'cutest' gui framework ever
       ;;racket            ; a DSL for DSLs
       ;;raku              ; the artist formerly known as perl6
       ;;rest              ; Emacs as a REST client
       ;;rst               ; ReST in peace
       ;;(ruby +rails)     ; 1.step {|i| p "Ruby is #{i.even? ? 'love' : 'life'}"}
       rust ;;(rust +lsp)       ; Fe2O3.unwrap().unwrap().unwrap().unwrap()
       ;;scala             ; java, but good
       ;;(scheme +guile)   ; a fully conniving family of lisps
       sh                ; she sells {ba,z,fi}sh shells on the C xor
       ;;sml
       ;;solidity          ; do you need a blockchain? No.
       ;;swift             ; who asked for emoji variables?
       ;;terra             ; Earth and Moon in alignment for performance.
       ;;web               ; the tubes
       yaml              ; JSON, but readable
       ;;zig               ; C, but simpler

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

       :app
       ;;calendar
       ;;emms
       ;;everywhere        ; *leave* Emacs!? You must be joking
       ;;irc               ; how neckbeards socialize
       ;;(rss +org)        ; emacs as an RSS reader
       ;;twitter           ; twitter client https://twitter.com/vnought

       :config
       literate
       (default +bindings +smartparen))
      #+end_src

#+RESULTS:

* Config
** default

#+begin_src emacs-lisp :tangle "config.el"
;;; config.el -*- lexical-binding: t; -*-
(setq enable-local-variables :all)
#+end_src

** ui :ui:
#+begin_src emacs-lisp :tangle "config.el"
;; This determines the style of line numbers in effect. If set to `nil', line
;; numbers are disabled. For relative line numbers, set this to `relative'.
(setq display-line-numbers-type t)

(pixel-scroll-precision-mode 1)
(setq pixel-scroll-precision-interpolate-page t)
(defalias 'scroll-up-command 'pixel-scroll-interpolate-up)
(defalias 'scroll-down-command 'pixel-scroll-interpolate-down)
#+end_src

** misc

#+begin_src emacs-lisp :tangle "~/.doom.d/autoload/+misc.el"
;;; ~/.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")
  )
#+end_src

#+RESULTS:
: insert-current-date-time-active

** highlight

*** indent
#+begin_src emacs-lisp :tangle "packages.el"
(package! indent-bars :recipe (:host github :repo "jdtsmith/indent-bars"))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
;; (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")
;;   )
(use-package indent-bars
  :custom
  (indent-bars-treesit-support t)
  (indent-bars-no-descend-string t)
  (indent-bars-treesit-ignore-blank-lines-types '("module"))
  (indent-bars-treesit-wrap '((python argument_list parameters ; for python, as an example
				      list list_comprehension
				      dictionary dictionary_comprehension
				      parenthesized_expression subscript)))
   :hook ((python-base-mode fingertip-mode nickel-mode) . indent-bars-mode))
#+end_src

** tab
#+begin_src emacs-lisp :tangle "packages.el"
(package! sort-tab :recipe (:host github :repo "manateelazycat/sort-tab"))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package! sort-tab
  :config
  (add-hook '+doom-dashboard-mode-hook
    (lambda () (sort-tab-mode 1)))
  )
#+end_src

** font :font:

#+begin_src emacs-lisp :tangle "config.el"
;; Font
;; (setq doom-font (font-spec :family "Fantasque Sans Mono" :size 15))
(setq doom-variable-pitch-font (font-spec :family "Fantasque Sans Mono"))
;; (setq doom-big-font (font-spec :family "Fantasque Sans Mono"
;;                            :size 17))
;; (setq doom-unicode-font doom-font)

(when (display-graphic-p)
(set-face-attribute
   'default nil
   :font (font-spec
          :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 (cond (IS-LINUX "Weibei SC")
                            (IS-MAC "Weibei TC"))
                :weight 'normal
                :slant 'normal
                :size 24.5))))


(when IS-MAC
(defun init-cjk-fonts()
  (dolist (charset '(kana han cjk-misc bopomofo))
    (set-fontset-font (frame-parameter nil 'font)
      charset (font-spec :family "Weibei SC" :size 24.5))))
(when (display-graphic-p)
(add-hook 'doom-init-ui-hook 'init-cjk-fonts)))
#+end_src

#+RESULTS:
| init-cjk-fonts | persp-mode | window-divider-mode | +doom-dashboard-init-h | +popup-mode |

** doom-theme :theme:

#+begin_src emacs-lisp :tangle "config.el"
;; (unless (display-graphic-p)
;;   ;;(setq doom-theme 'doom-city-lights)
;;   (setq doom-theme 'doom-one)
;; )
(when (display-graphic-p)
  (setq doom-theme 'doom-one)
)
#+end_src

#+RESULTS:
: doom-city-lights

** popup rules :window:

#+begin_src emacs-lisp :tangle "config.el"
(set-popup-rules! '(
  ("^\\*helpful" :size 0.5)
  ("^\\*info.*" :size 80 :size right)
  ))
#+end_src

** personal

#+begin_src emacs-lisp :tangle "config.el"
(setq user-full-name "GuangTao Zhang"
      user-mail-address "gtrunsec@hardenedlinux.org")
#+end_src

** scroll :scroll:window:

#+begin_src emacs-lisp :tangle "config.el"
(setq scroll-margin 15
      scroll-conservatively 101
      scroll-up-aggressively 0.01
      scroll-down-aggressively 0.01
      scroll-preserve-screen-position t
      auto-window-vscroll nil)
#+end_src

** dired :file:

#+begin_src emacs-lisp :tangle "config.el"
(add-hook 'dired-mode-hook (lambda () (dired-async-mode 1)))
#+end_src

** chinese
** parentheses :ui:

- [[https://with-emacs.com/posts/ui-hacks/show-matching-lines-when-parentheses-go-off-screen/][with-emacs · Show matching lines when parentheses go off-screen]]s

- [[https://www.reddit.com/r/emacs/comments/bqyx6h/withemacs_show_matching_lines_when_parentheses_go/][(with-emacs · Show matching lines when parentheses go off-screen : emacs]]

#+begin_src emacs-lisp :tangle "show-parentheses.el"
;;; -*- 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)
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(load! "show-parentheses.el")
#+end_src

** auto-save :save:buffer:

#+begin_src emacs-lisp :tangle "packages.el"
(package! auto-save :recipe (:host github :repo "manateelazycat/auto-save"))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(add-hook! 'before-save-hook 'font-lock-flush)

(use-package! auto-save
  :init
  (setq auto-save-silent t)   ; quietly save
  ;; after foraml-buffer
  (setq auto-save-idle 5)
  (setq auto-save-delete-trailing-whitespace nil)  ; automatically delete spaces at the end of the line when saving
;;; disable auto save mode when current filetype is an gpg file.
  :config
  (auto-save-enable)
  (setq auto-save-disable-predicates
        '((lambda ()
            (string-suffix-p
             "gpg"
             (file-name-extension (buffer-name)) t))))
  )
#+end_src

** vundo :undo:
- https://github.com/casouri/vundo

#+begin_src emacs-lisp :tangle "packages.el"
(unpin! vundo)
#+end_src

** electric-align :indent:align:

#+begin_src emacs-lisp :tangle "packages.el"
(package! electric-align :recipe (:host github :repo "zk-phi/electric-align"))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package! electric-align)
#+end_src


* Packages

#+begin_src emacs-lisp :tangle "packages.el"
(package! with-editor
          :recipe (:host github :repo "magit/with-editor"
                         :branch "main"))
#+end_src
** writing room :writing:

#+begin_src emacs-lisp :tangle "config.el"
(use-package writeroom-mode
  :hook
  (org-mode . writeroom-mode)
  (w3m-mode . writeroom-mode)
  (markdown-mode . writeroom-mode)
  :config
  (setq +zen-text-scale 0)
  ;; (setq +zen-window-divider-size 2)
  ;; (advice-add 'text-scale-adjust :after
  ;;             #'visual-fill-column-adjust)

  ;;https://github.com/joostkremers/writeroom-mode#fullscreen-effect
  (setq writeroom-fullscreen-effect 'maximized)
  (setq writeroom-width 75)
  )
#+end_src

** blink search :search:

#+begin_src emacs-lisp :tangle "packages.el"
(package! blink-search :recipe (:host github :repo "manateelazycat/blink-search"
                                ;;:build (:not compile)
                                :files ("*")))
#+end_src


#+begin_src emacs-lisp :tangle "config.el"
(use-package blink-search
  :config
  (setq blink-search-python-command "/run/current-system/sw/bin/python3")
  ;; (setq blink-search-posframe-standalone t)
  ;; (setq blink-search-enable-posframe t)
  ;; (setq blink-search-search-backends '("Buffer List" "Recent File" "IMenu" "Elisp Symbol" "Key Value"))
  (add-hook 'blink-search-mode-hook (lambda () (meow-insert-mode
 1))))
#+end_src

#+RESULTS:
: t


** symbol-overlay :search:

#+begin_src emacs-lisp :tangle "packages.el"
(package! symbol-overlay)
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package symbol-overlay
  :config
  :bind (:map symbol-overlay-mode-map
              ("M-i" . symbol-overlay-put)
              ("M-N" . symbol-overlay-switch-forward)
              ("M-P" . symbol-overlay-switch-backward)
              ("M-n" . symbol-overlay-jump-next)
              ("M-p" . symbol-overlay-jump-prev)
              ("M-r" . symbol-overlay-query-replace)
              ("M-R" . symbol-overlay-rename)))
#+end_src

** org-sliced-images :image:

#+begin_src emacs-lisp :tangle "packages.el"
(package! org-sliced-images :recipe (:host github :repo "jcfk/org-sliced-images"))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package! org-sliced-images
  :hook (org-mode . org-sliced-images-mode))
#+end_src


* crux :misc:
#+begin_src emacs-lisp :tangle "packages.el"
(package! crux :recipe (:host github :repo "bbatsov/crux"))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package! crux)
#+end_src



** orderless :completion:

#+begin_src emacs-lisp :tangle "packages.el"
(unpin! orderless)
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package orderless
  :init
  ;; Configure a custom style dispatcher (see the Consult wiki)
  ;; (setq orderless-style-dispatchers '(+orderless-dispatch)
  ;;       orderless-component-separator #'orderless-escapable-split-on-space)
  (setq ;;completion-styles '(orderless basic)
   completion-category-defaults nil
   completion-category-overrides '((file (styles . (partial-completion))))))
#+end_src

** consult :search:

#+begin_src emacs-lisp :tangle "packages.el"
;;(unpin! consult)
#+end_src

** color-rg :search:

#+begin_src emacs-lisp :tangle "packages.el"
(package! color-rg :recipe (:host github :repo "manateelazycat/color-rg"))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(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))
  )
#+end_src


** pretty-hydra

#+begin_src emacs-lisp :tangle "packages.el"
(package! pretty-hydra :recipe (:host github
                                    :repo "jerrypnz/major-mode-hydra.el"
                                    :files ("*")
                                    ))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
;; copyright https://github.com/seagle0128/.emacs.d
(defun icon-displayable-p ()
  "Return non-nil if icons are displayable."
  (or (display-graphic-p) (daemonp))
  (or (featurep 'all-the-icons)
      (require 'all-the-icons nil t)))

(use-package! pretty-hydra
  :bind ("M-SPC" . major-mode-hydra)
  :hook (emacs-lisp-mode . (lambda ()
                             (add-to-list
                              'imenu-generic-expression
                              '("Hydras"
                                "^.*(\\(pretty-hydra-define\\) \\([a-zA-Z-]+\\)"
                                2))))
  :init
  (cl-defun pretty-hydra-title (title &optional icon-type icon-name
                                      &key face height v-adjust)
    "Add an icon in the hydra title."
    (let ((face (or face `(:foreground ,(face-background 'highlight))))
          (height (or height 1.0))
          (v-adjust (or v-adjust 0.0)))
      (concat
       (when (and (icon-displayable-p) icon-type icon-name)
         (let ((f (intern (format "all-the-icons-%s" icon-type))))
           (when (fboundp f)
             (concat
              (apply f (list icon-name :face face :height height :v-adjust v-adjust))
              " "))))
       (propertize title 'face face))))

  ;; Global toggles
  (with-no-warnings
    (pretty-hydra-define toggles-hydra (:title (pretty-hydra-title "Toggles" 'faicon "toggle-on" :v-adjust -0.1)
                                        :color amaranth :quit-key ("q" "C-g"))
      ("Basic"
       (("n" (cond ((fboundp 'display-line-numbers-mode)
                    (display-line-numbers-mode (if display-line-numbers-mode -1 1)))
                   ((fboundp 'gblobal-linum-mode)
                    (global-linum-mode (if global-linum-mode -1 1))))
         "line number"
         :toggle (or (bound-and-true-p display-line-numbers-mode)
                     (bound-and-true-p global-linum-mode)))
        ("a" global-aggressive-indent-mode "aggressive indent" :toggle t)
        ("d" global-hungry-delete-mode "hungry delete" :toggle t)
        ("e" electric-pair-mode "electric pair" :toggle t)
        ("c" flyspell-mode "spell check" :toggle t)
        ("s" prettify-symbols-mode "pretty symbol" :toggle t)
        ("l" global-page-break-lines-mode "page break lines" :toggle t)
        ("b" display-battery-mode "battery" :toggle t)
        ("i" display-time-mode "time" :toggle t)
        ("m" doom-modeline-mode "modern mode-line" :toggle t))
       "Highlight"
       (("h l" global-hl-line-mode "line" :toggle t)
        ("h p" show-paren-mode "paren" :toggle t)
        ("h s" symbol-overlay-mode "symbol" :toggle t)
        ("h r" rainbow-mode "rainbow" :toggle t)
        ("h w" (setq-default show-trailing-whitespace (not show-trailing-whitespace))
         "whitespace" :toggle show-trailing-whitespace)
        ("h d" rainbow-delimiters-mode "delimiter" :toggle t)
        ("h i" highlight-indent-guides-mode "indent" :toggle t)
        ("h t" global-hl-todo-mode "todo" :toggle t))
       "Program"
       (("f" flycheck-mode "flycheck" :toggle t)
        ("F" flymake-mode "flymake" :toggle t)
        ("O" hs-minor-mode "hideshow" :toggle t)
        ("u" subword-mode "subword" :toggle t)
        ("W" which-function-mode "which function" :toggle t)
        ("E" toggle-debug-on-error "debug on error" :toggle (default-value 'debug-on-error))
        ("Q" toggle-debug-on-quit "debug on quit" :toggle (default-value 'debug-on-quit))
        ("v" global-diff-hl-mode "gutter" :toggle t)
        ("V" diff-hl-flydiff-mode "live gutter" :toggle t)
        ("M" diff-hl-margin-mode "margin gutter" :toggle t)
        ("D" diff-hl-dired-mode "dired gutter" :toggle t))
       "Theme"
       (("t a" (doom-load-theme 'auto) "auto"
         :toggle (eq doom-theme 'auto) :exit t)
        )))))
#+end_src

#+RESULTS:
: major-mode-hydra

** goggles :highlights:modify:region:

#+begin_src emacs-lisp :tangle "packages.el"
(package! goggles :recipe (:host github :repo "minad/goggles"))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package! goggles
  :hook ((prog-mode text-mode) . goggles-mode)
  :config
  (setq-default goggles-pulse t))
#+end_src

** yatemplate
#+begin_src emacs-lisp :tangle "packages.el"
(package! yatemplate)
#+end_src
- [[https://github.com/mineo/yatemplate][mineo/yatemplate: Simple file templates for Emacs with YASnippet]]
#+begin_src emacs-lisp :tangle "config.el"
(use-package! yatemplate
  :after yasnippet
  :config
  ;; Define template directory
  (setq yatemplate-dir (concat doom-private-dir "templates"))
  ;; Coupling with auto-insert
  (setq auto-insert-alist nil)
  (yatemplate-fill-alist)
  (add-hook 'find-file-hook 'auto-insert)
  )
#+end_src



** mind-wave :chatgpt:

#+begin_src emacs-lisp :tangle "packages.el"
(package! mind-wave :recipe (:host github :repo "manateelazycat/mind-wave"
                                   :files ("*")
                                   ))
#+end_src


#+begin_src emacs-lisp :tangle "config.el"
(use-package! mind-wave
  :commands (mind-wave-chat-mode)
  :hook (mind-wave-chat-mode . visual-fill-column-mode))
#+end_src

** visual-fill-column :fill:visual:
** separedit.el :comment:edit:

#+begin_src emacs-lisp :tangle "packages.el"
(package! separedit :recipe (:host github :repo "twlz0ne/separedit.el"))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package! separedit
  :config
  (define-key prog-mode-map        (kbd "C-x '") #'separedit)
  (define-key minibuffer-local-map (kbd "C-x '") #'separedit)
  ;;(define-key org-src-mode-map     (kbd "C-x '") #'separedit)
  )
#+end_src

** jinx :spellCheck:

#+begin_src emacs-lisp :tangle "packages.el"
(package! jinx :recipe (:host github :repo "minad/jinx"
                        :files ("*")))
#+end_src

- to show the list of available dictionaries

in jinx-mode.c I replaced the line #include <enchant.h> with #include "/opt/homebrew/include/enchant-2/enchant.h"
#+begin_src sh :tangle no
enchant-lsmod-2
#+end_src

#+RESULTS:

#+begin_src emacs-lisp :tangle "config.el"
  (use-package! jinx
    :defer t
    :config
    (jinx--load-module)
    (add-to-list 'jinx-exclude-regexps '(t "\\cc")) ;; chinese
    (dolist (hook '(text-mode-hook prog-mode-hook conf-mode-hook
                    org-mode-hook ))
      (add-hook hook #'jinx-mode)))
#+end_src


** vlf :file:large:
#+begin_src emacs-lisp :tangle "packages.el"
(package! vlf)
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package! vlf
  :config
  (require 'vlf-setup)
  (custom-set-variables
   '(vlf-application 'dont-ask))
  )
#+end_src


** d2-mode :d2:diagrams:
#+begin_src emacs-lisp :tangle "packages.el"
(package! d2-mode)
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package! d2-mode
  :config
  (add-to-list 'auto-mode-alist (cons "\\.d2\\'" 'd2-mode)))
#+end_src


*** ob-d2 :d2:diagrams:orgmode:
#+begin_src emacs-lisp :tangle "packages.el"
(package! ob-d2)
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package! ob-d2)
#+end_src


** [[https://github.com/xenodium/chatgpt-shell][xenodium/chatgpt-shell: ChatGPT and DALL-E Emacs shells + Org babel 🦄 + a shell maker for other providers]]

- [blog] https://xenodium.com/

#+begin_src emacs-lisp :tangle "packages.el"
(package! chatgpt-shell :recipe (:host github :repo "xenodium/chatgpt-shell"
                                       :files ("*.el")
                                       ))
(package! shell-maker :recipe (:host github :repo "xenodium/chatgpt-shell"
                               :files ("shell-maker.el")
        ))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package! chatgpt-shell
  :defer t
  :init
  (require 'dall-e-shell)
  (require 'ob-chatgpt-shell)
  (require 'ob-dall-e-shell)
  :config
  (require 'f)
  (setq chatgpt-shell-chatgpt-streaming t)
  ;;(setq chatgpt-shell-openai-key (read-export-value "<PATH>" "OPENAI_ACCESS_TOKEN")))
  (setq chatgpt-shell-openai-key (substring (f-read-text
                                  (concat doom-cache-dir
                                          "/mind-wave/chatgpt_api_key.txt") 'utf-8) 0 -1))
  )
#+end_src


** https://github.com/dalanicolai/image-roll.el :scroll:image:
#+begin_src emacs-lisp :tangle "packages.el"
;; (package! image-roll :recipe (:host github :repo "dalanicolai/image-roll.el"
;;                                     :files ("*.el")
;;                                        ))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
;;(use-package! image-roll)
#+end_src

** dirvish :dired:

#+Begin_src emacs-lisp :tangle "packages.el"
(unpin! dirvish)
(package! dirvish)
#+end_src

** direnv

#+begin_src emacs-lisp :tangle "packages.el"
;;(package! direnv)
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
;; (use-package! direnv
;;   :if (executable-find "direnv")
;;   :config
;;   (direnv-mode)
;;   (defcustom dn-direnv-enabled-hosts nil
;;     "List of remote hosrs to use direnv on.

;;      Each host must have the `direnv` executable accessible in the default environment"
;;     :type '(repeat string)
;;     :group 'dn)

;;   (defun tramp-sh-handle-start-file-process@dn-direnv (args)
;;     "Enable Direnv for hosts in `dn-direnv-enabled-hosts'."
;;     (message "tramp-sh-handle-start-file-process@dn-direnv")
;;     (with-parsed-tramp-file-name (expand-file-name default-directory) nil
;;       (if (member host my-direnv-enabled-hosts)
;;           (pcase-let ((`(,name ,buffer ,program . ,args) args))
;;             `(,name
;;               ,buffer
;;               "direnv"
;;               "exec"
;;               ,localname
;;               ,program
;;               ,@args))
;;         args)))

;;   (with-eval-after-load "tramp-sh"
;;     (advice-add 'tramp-sh-handle-start-file-process
;;                 :filter-args #'tramp-sh-handle-start-file-process@dn-direnv))
;;   )
#+end_src


** eaf
#+begin_src emacs-lisp :tangle "packages.el"
(when IS-LINUX
  (package! epc :recipe (:build (:not compile)))
  (package! eaf :recipe (:host github
                         :repo "emacs-eaf/emacs-application-framework"
                         :files ("*")
                         :build (:not compile)
                         ))
  (package! eaf-file-manager :recipe (:host github
                         :repo "emacs-eaf/eaf-file-manager"
                         :files ("*"))
  ))
#+end_src


#+begin_src emacs-lisp :tangle "config.el"
;; (when IS-LINUX
;;   (when (display-graphic-p)
;;     (use-package! eaf
;;       :if (eq system-type 'gnu/linux)
;;       :init
;;          :custom
;;       ;; See https://github.com/emacs-eaf/emacs-application-framework/wiki/Customization
;;       (eaf-browser-continue-where-left-off t)
;;       (eaf-browser-enable-adblocker t)
;;       (browse-url-browser-function 'eaf-open-browser)
;;       :config
;;       (require' eaf-file-manager)
;;       (setq eaf-webengine-default-zoom 2.0)
;;       (setq eaf-python-command "/run/current-system/sw/bin/python")
;;       ;;(eaf-bind-key scroll_up "C-n" eaf-pdf-viewer-keybinding)
;;       ;;(eaf-bind-key scroll_down "C-p" eaf-pdf-viewer-keybinding)
;;       )
;;     (use-package! epc)
;;     )
;;   )
#+end_src


** Disabled Packages

#+begin_src emacs-lisp :tangle "packages.el"
(disable-packages! tree-sitter-langs)
(disable-packages! doom-snippets)
#+end_src


* Org

** package :latex:

- https://emacs-china.org/t/org-mode-latex-improved-latex-preview/23742/15?u=gtrunsec
#+begin_src emacs-lisp :tangle "packages.el"
;; (package! org :recipe
;;   (:host nil :repo "https://git.tecosaur.net/mirrors/org-mode.git" :remote "mirror" :fork
;;          (:host nil :repo "https://git.tecosaur.net/tec/org-mode.git" :branch "dev" :remote "tecosaur")
;;          :files
;;          (:defaults "etc")
;;          :build t :pre-build
;;          (with-temp-file "org-version.el"
;;            (require 'lisp-mnt)
;;            (let
;;                ((version
;;                  (with-temp-buffer
;;                    (insert-file-contents "lisp/org.el")
;;                    (lm-header "version")))
;;                 (git-version
;;                  (string-trim
;;                   (with-temp-buffer
;;                     (call-process "git" nil t nil "rev-parse" "--short" "HEAD")
;;                     (buffer-string)))))
;;              (insert
;;               (format "(defun org-release () \"The release version of Org.\" %S)\n" version)
;;               (format "(defun org-git-version () \"The truncate git commit hash of Org mode.\" %S)\n" git-version)
;;               "(provide 'org-version)\n"))))
;;   :pin nil)

;; (unpin! org)
#+end_src


** default

#+begin_src emacs-lisp :tangle "config.el"
(setq org-directory "~/ghq/github.com/GTrunSec/org-notes")


(after! org
;;https://orgmode.org/worg/org-contrib/babel/examples/fontify-src-code-blocks.html
  (defun org-only-show-headings ()
    (interactive)
    (org-content -1))
  (add-hook! 'org-mode-hook 'org-only-show-headings)

  (add-hook! 'org-mode-hook 'auto-revert-mode)
  (add-hook! 'dired-mode-hook 'org-download-enable)
  (add-hook! 'org-mode-hook 'org-only-show-headings)
  (add-hook! 'unpackaged/org-return-dwim 'unpackaged/org-fix-blank-lines)
  )
#+end_src


#+begin_src emacs-lisp :tangle "config.el"
;; copyright https://github.com/seagle0128/.emacs.d
(defun hot-expand (str &optional mod)
    "Expand org template.

STR is a structure template string recognised by org like <s. MOD is a
string with additional parameters to add the begin line of the
structure element. HEADER string includes more parameters that are
prepended to the element after the #+HEADER: tag."
    (let (text)
      (when (region-active-p)
        (setq text (buffer-substring (region-beginning) (region-end)))
        (delete-region (region-beginning) (region-end)))
      (insert str)
      (if (fboundp 'org-try-structure-completion)
          (org-try-structure-completion) ; < org 9
        (progn
          ;; New template expansion since org 9
          (require 'org-tempo nil t)
          (org-tempo-complete-tag)))
      (when mod (insert mod) (forward-line))
      (when text (insert text))))

(major-mode-hydra-define org-mode
  ;; See `org-structure-template-alist'
  (:title (pretty-hydra-title "Org Template" 'fileicon "org" :face 'all-the-icons-green :height 1.1 :v-adjust 0.0)
    :color blue :quit-key ("q" "C-g"))
     ("Basic"
    (("a" (hot-expand "<a") "ascii")
     ("c" (hot-expand "<c") "center")
     ("C" (hot-expand "<C") "comment")
     ("e" (hot-expand "<e") "example")
     ("E" (hot-expand "<E") "export")
     ("h" (hot-expand "<h") "html")
     ("l" (hot-expand "<l") "latex")
     ("n" (hot-expand "<n") "note")
     ("o" (hot-expand "<q") "quote")
     ("v" (hot-expand "<v") "verse"))
    "Head"
    (("i" (hot-expand "<i") "index")
     ("A" (hot-expand "<A") "ASCII")
     ("I" (hot-expand "<I") "INCLUDE")
     ("H" (hot-expand "<H") "HTML")
     ("L" (hot-expand "<L") "LaTeX"))
    "Source"
    (("s" (hot-expand "<s") "src")
     ("m" (hot-expand "<s" "emacs-lisp") "emacs-lisp")
     ("p" (hot-expand "<s" "python :results output") "python")
     ;;emacs-jupyter
     ("jp" (hot-expand "<s" "jupyter-python") "jupyter-python")
     ("jh" (hot-expand "<s" "jupyter-haskell") "jupyter-haskell")
     ("jj" (hot-expand "<s" "jupyter-julia") "jupyter-julia")
     ("jb" (hot-expand "<s" "jupyter-bash") "jupyter-bash")
     ("w" (hot-expand "<s" "powershell") "powershell")
     ("r" (hot-expand "<s" "ruby") "ruby")
     ("S" (hot-expand "<s" "sh") "sh")
     ("gs" (hot-expand "<s" "chatgpt-shell") "text")
     ("gl" (hot-expand "<s" "go :imports '\(\"fmt\"\)") "golang"))
    "Misc"
    (("u" (hot-expand "<s" "plantuml :file CHANGE.png") "plantuml")
     ("Y" (hot-expand "<s" "ipython :session :exports both :results raw drawer\n$0") "ipython")
     ;; ("<" self-insert-command "ins")
     )))
#+end_src

#+RESULTS:
: major-mode-hydras/org-mode/body



** org-modern :theme:

#+begin_src emacs-lisp :tangle  "packages.el"
(package! org-modern :recipe (:host github :repo "minad/org-modern"
                              :files ("*.el")
                              )
  :pin "5b6b53ecfba6c8da2407b2cfbeeaecab8cf83e26")
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package! org-modern
  :hook
  (org-mode . org-modern-mode)
  (org-agenda-finalize . org-modern-agenda)
  :custom
  (org-modern-hide-stars nil) ; adds extra indentation
  )
#+end_src

*** org-modern-indent :indent:
#+begin_src emacs-lisp :tangle  "packages.el"
(package! org-modern-indent :recipe (:host github :repo "jdtsmith/org-modern-indent"))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package! org-modern-indent
  :config
  (add-hook 'org-mode-hook #'org-modern-indent-mode 90))
#+end_src

** org-cv
#+begin_src emacs-lisp :tangle  "packages.el"
(package! ox-moderncv :recipe (:host gitlab :repo "Titan-C/org-cv"
                              :files ("*.el")))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package! ox-moderncv
  :init
  (require 'ox-awesomecv)
  (require 'ox-altacv))
#+end_src

#+RESULTS:
: ox-moderncv

** org-roam :roam:

#+begin_src emacs-lisp :tangle "packages.el"
(unpin! org-roam)
#+end_src


#+begin_src emacs-lisp :tangle "config.el"
(use-package! org-roam
  :config
  (setq org-roam-directory (concat org-directory "/braindump"))
  )
#+end_src

** org-super-agenda :agenda:

#+begin_src emacs-lisp :tangle "packages.el"
(package! org-super-agenda)
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package! org-super-agenda
  :hook
  (after-init . org-super-agenda-mode)
  :init
  (require 'org-habit)
  :config
  (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)
  )
#+end_src


** consult-notes :roam:search:

- https://github.com/mclear-tools/consult-notes

#+begin_src emacs-lisp :tangle  "packages.el"
(package! consult-notes :recipe (:host github :repo "mclear-tools/consult-notes"))
#+end_src


#+begin_src emacs-lisp :tangle "config.el"
(use-package! consult-notes
  :hook
  (org-mode . consult-notes-org-roam-mode)
  :commands (consult-notes
             consult-notes-search-in-all-notes
             consult-notes-org-roam-find-node
             consult-notes-org-roam-find-node-relation)
  :config
  (setq consult-notes-sources '(("Org Braindump"
                                 ?b  "~/ghq/github.com/GTrunSec/org-notes/braindump")))
  ;; Set notes dir(s), see below
  )

  #+end_src

** org-navigator :refile:

- https://github.com/thread314/org-navigator

#+begin_src emacs-lisp :tangle  "packages.el"
(package! org-navigator :recipe (:host github :repo "thread314/org-navigator"))
#+end_src


#+begin_src emacs-lisp :tangle "config.el"
(use-package! org-navigator
  :config
  (setq org-navigator-key-map org-mode-map
   org-navigator-fold-first t
        org-navigator-set-view t
        org-navigator-all-shortcuts '()
        org-navigator-duplicates '()
        org-navigator-config-file "~/ghq/github.com/GTrunSec/hive/profiles/doom-emacs/org-navigator/shortcut-definitions.el"
        org-navigator-file-to-prefix "C-c f"
        org-navigator-go-to-prefix "C-c g"
        org-navigator-open-and-narrow-prefix "C-c n"
        org-navigator-open-in-indirect-prefix "C-c i"
        org-navigator-clock-in-prefix "C-c c"))

  #+end_src


** chatgpt

#+begin_src emacs-lisp :tangle "packages.el"
;; (package! chatgpt
;;   :recipe (:host github :repo "joshcho/ChatGPT.el" :files ("dist" "*.el")))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
;; (use-package! chatgpt
;;   :defer t
;;   :config
;;   (unless (boundp 'python-interpreter)
;;     (defvaralias 'python-interpreter 'python-shell-interpreter))
;;   (setq chatgpt-repo-path (expand-file-name "straight/repos/ChatGPT.el/" doom-local-dir))
;;   (set-popup-rule! (regexp-quote "*ChatGPT*")
;;     :side 'bottom :size .5 :ttl nil :quit t :modeline nil)
;;   :bind ("C-c q" . chatgpt-query))
#+end_src


** ox-clip :copy:formatter:

#+begin_src emacs-lisp :tangle "packages.el"
(package! ox-clip
  :recipe (:host github :repo "jkitchin/ox-clip"))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package! ox-clip)
#+end_src

** dotask

#+begin_src emacs-lisp :tangle "config.el"
(load! "+dotsk.el")
#+end_src


+ copyright & sources:
 - https://emacs-china.org/t/dot/23800/2
 - https://medium.com/@zeruhur/making-sketchy-diagrams-on-your-local-machine-903d13e20a13

#+begin_src emacs-lisp :tangle "+dotsk.el"
;;; dotsk.el --- Babel Functions for dot            -*- lexical-binding: t; -*-

;; Copyright (C) 2009-2022 Free Software Foundation, Inc.

;; Author: Eric Schulte
;; Maintainer: Justin Abrahms <justin@abrah.ms>
;; Keywords: literate programming, reproducible research
;; URL: https://orgmode.org

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; Org-Babel support for evaluating dot source code.
;;
;; For information on dot see https://www.graphviz.org/
;;
;; This differs from most standard languages in that
;;
;; 1) there is no such thing as a "session" in dot
;;
;; 2) we are generally only going to return results of type "file"
;;
;; 3) we are adding the "file" and "cmdline" header arguments
;;
;; 4) there are no variables (at least for now)

;;; Code:

(require 'org-macs)
(org-assert-version)
(defvar org-babel-default-header-args:dotsk
  '((:results . "file") (:exports . "results"))
  "Default arguments to use when evaluating a dot source block.")

(defun org-babel-expand-body:dotsk (body params)
  "Expand BODY according to PARAMS, return the expanded body."
  (let ((vars (org-babel--get-vars params)))
    (mapc
     (lambda (pair)
       (let ((name (symbol-name (car pair)))
	     (value (cdr pair)))
	 (setq body
	       (replace-regexp-in-string
		(concat "$" (regexp-quote name))
		(if (stringp value) value (format "%S" value))
		body
		t
		t))))
     vars)
    body))

(defun org-babel-execute:dotsk (body params)
  " This function is called by `org-babel-execute-src-block'."
  (let* ((out-file (cdr (or (assq :file params)
			    (error "You need to specify a :file parameter"))))
	 (cmdline (or (cdr (assq :cmdline params))))
	 (cmd (or (cdr (assq :cmd params)) (concat "dotsk " doom-user-dir "static/sketchviz/sketch.js")))
	 (coding-system-for-read 'utf-8) ;use utf-8 with sub-processes
	 (coding-system-for-write 'utf-8)
	 (in-file (org-babel-temp-file "dotsk-")))
    (with-temp-file in-file
      (insert (org-babel-expand-body:dotsk body params)))
    (org-babel-eval
     (concat cmd
	     " " (org-babel-process-file-name in-file)
	     " " cmdline
	     " " (org-babel-process-file-name out-file)) "")
    nil)) ;; signal that output has already been written to file

(defun org-babel-prep-session:dotsk (_session _params)
  "Return an error because Dot does not support sessions."
  (error "Dot does not support sessions"))

;; Support org-mode, when adding a code block for dotsk, use this mode
(with-eval-after-load 'org-src
  (defvar org-src-lang-modes)
  (add-to-list 'org-src-lang-modes  '("dotsk" . graphviz-dot)))

(provide 'dotsk)
#+end_src



* Programming
** flycheck

#+begin_src emacs-lisp :tangle "custom.el"
(after! flycheck
  ;;(setq flycheck-check-syntax-automatically '(save mode-enabled))
  ;;(setq-default flycheck-disabled-checkers '(c/c++-clang))
  (global-flycheck-mode -1)
  )
#+end_src

** rust :rust:

#+begin_src emacs-lisp :tangle "config.el"
(after! rustic
  (setq rustic-indent-offset 4)
  (add-hook 'flycheck-mode-hook #'rustic-flycheck-setup)
  )
#+end_src

** copilot :completion:

#+begin_src emacs-lisp :tangle "packages.el"
(package! copilot
  :recipe (:host github :repo "zerolfx/copilot.el" :files ("*.el" "dist")))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package! copilot
  :config
(add-to-list 'copilot-indentation-alist `(prog-mode 4))
(add-to-list 'copilot-indentation-alist `(emacs-lisp-mode 4))
  ;; (add-to-list 'copilot-indentation-alist
  ;;                      '(nix-mode 2)
  ;;                      '(nickel-mode 2)
  ;;                      '(emacs-lisp-mode 4))
  :config
  ;;(setq copilot-node-executable "node16")
  :hook (prog-mode . copilot-mode)
  :bind ((:map copilot-completion-map
               ("C-e" . 'copilot-accept-completion)
               ("TAB" . 'copilot-accept-completion-by-word)
               ("<tab>" . 'copilot-accept-completion-by-word)
               ;;("LEFT" . 'copilot-accept-completion)
               )))
#+end_src

#+RESULTS:
: copilot-accept-completion-by-word


** codeium

#+begin_src emacs-lisp :tangle "packages.el"
;; (package! codeium :recipe (:host github :repo "Exafunction/codeium.el"))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
;; (use-package! codeium
;;   :init
;;   ;; use globally
;;   (add-to-list 'completion-at-point-functions #'codeium-completion-at-point)
;;   :config
;;   (setq use-dialog-box nil) ;; do not use popup boxes
;;   (setq codeium-api-enabled
;;         (lambda (api)
;;           (memq api '(GetCompletions Heartbeat CancelRequest GetAuthToken RegisterUser auth-redirect AcceptCompletion))))
;;   )
#+end_src

#+RESULTS:
: t

** quarto mode
#+begin_src emacs-lisp :tangle "packages.el"
(package! quarto-mode :recipe (:host github :repo "quarto-dev/quarto-emacs"))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package! quarto-mode
  ;;:mode (("\\.Rmd" . poly-quarto-mode))
  )
#+end_src



** ob-julia-vterm :julia:

#+begin_src emacs-lisp :tangle "packages.el"
(package! ob-julia-vterm :recipe (:host github :repo "shg/ob-julia-vterm.el"))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package! ob-julia-vterm
  :defer t
  :config
  (add-to-list 'org-babel-load-languages '(julia-vterm . t))
  (after! org
    (defalias 'org-babel-execute:julia 'org-babel-execute:julia-vterm)
    (defalias 'org-babel-variable-assignments:julia 'org-babel-variable-assignments:julia-vterm)))
#+end_src

** fingertip :treesit:

- https://github.com/manateelazycat/fingertip
#+begin_src emacs-lisp :tangle "packages.el"
(package! fingertip :recipe (:host github :repo "manateelazycat/fingertip"
                             ;;:build (:not compile)
                             :files ("*")))
(package! awesome-pair :recipe (:host github :repo "manateelazycat/awesome-pair"
                             ;;:build (:not compile)
                             :files ("*")))
#+end_src


#+begin_src emacs-lisp :tangle "config.el"
(use-package! fingertip
  :config
  (add-hook 'python-mode-hook #'python-ts-mode)
  (add-hook 'json-mode-hook #'json-ts-mode)
  (add-hook 'yaml-mode-hook #'yaml-ts-mode)
  (add-hook 'rust-mode-hook #'rust-ts-mode)
  (add-hook 'sh-mode-hook #'bash-ts-mode)
  (add-hook 'java-mode-hook #'java-ts-mode)

  (dolist (hook (list
                 'c-mode-common-hook
                 'c-mode-hook
                 'c++-mode-hook
                 'java-mode-hook
                 'haskell-mode-hook
                 ;;'emacs-lisp-mode-hook
                 'lisp-interaction-mode-hook
                 'lisp-mode-hook
                 'maxima-mode-hook
                 'ielm-mode-hook
                 'sh-mode-hook
                 'makefile-gmake-mode-hook
                 'php-mode-hook
                 'python-mode-hook
                 'js-mode-hook
                 'go-mode-hook
                 'qml-mode-hook
                 'jade-mode-hook
                 'css-mode-hook
                 'ruby-mode-hook
                 'coffee-mode-hook
                 'rust-mode-hook
                 'rust-ts-mode-hook
                 'qmake-mode-hook
                 'lua-mode-hook
                 'swift-mode-hook
                 'minibuffer-inactive-mode-hook
                 'typescript-mode-hook
                 'c-ts-mode-hook
                 'c++-ts-mode-hook
                 'cmake-ts-mode-hook
                 'toml-ts-mode-hook
                 'css-ts-mode-hook
                 'js-ts-mode-hook
                 'json-ts-mode-hook
                 'python-ts-mode-hook
                 'bash-ts-mode-hook
                 'typescript-ts-mode-hook
                 'nix-ts-mode
                 ))
    (add-hook hook '(lambda () (fingertip-mode 1))))

  (define-key fingertip-mode-map (kbd "(") 'fingertip-open-round)
  (define-key fingertip-mode-map (kbd "[") 'fingertip-open-bracket)
  (define-key fingertip-mode-map (kbd "{") 'fingertip-open-curly)
  (define-key fingertip-mode-map (kbd ")") 'fingertip-close-round)
  (define-key fingertip-mode-map (kbd "]") 'fingertip-close-bracket)
  (define-key fingertip-mode-map (kbd "}") 'fingertip-close-curly)
  (define-key fingertip-mode-map (kbd "=") 'fingertip-equal)

  (define-key fingertip-mode-map (kbd "%") 'fingertip-match-paren)
  (define-key fingertip-mode-map (kbd "\"") 'fingertip-double-quote)
  (define-key fingertip-mode-map (kbd "'") 'fingertip-single-quote)

  (define-key fingertip-mode-map (kbd "SPC") 'fingertip-space)
  (define-key fingertip-mode-map (kbd "RET") 'fingertip-newline)

  (define-key fingertip-mode-map (kbd "M-o") 'fingertip-backward-delete)
  (define-key fingertip-mode-map (kbd "C-d") 'fingertip-forward-delete)
  (define-key fingertip-mode-map (kbd "C-k") 'fingertip-kill)

  (define-key fingertip-mode-map (kbd "M-\"") 'fingertip-wrap-double-quote)
  (define-key fingertip-mode-map (kbd "M-'") 'fingertip-wrap-single-quote)
  ;;(define-key fingertip-mode-map (kbd "M-[") 'fingertip-wrap-bracket)
  (define-key fingertip-mode-map (kbd "M-{") 'fingertip-wrap-curly)
  (define-key fingertip-mode-map (kbd "M-(") 'fingertip-wrap-round)
  (define-key fingertip-mode-map (kbd "M-)") 'fingertip-unwrap)

  (define-key fingertip-mode-map (kbd "M-p") 'fingertip-jump-right)
  (define-key fingertip-mode-map (kbd "M-n") 'fingertip-jump-left)
  (define-key fingertip-mode-map (kbd "M-:") 'fingertip-jump-out-pair-and-newline)

  (define-key fingertip-mode-map (kbd "C-j") 'fingertip-jump-up)
  )
  #+end_src

  #+RESULTS:
  : t



** typst-mode :typst:mathematic:

- https://github.com/manateelazycat/fingertip
#+begin_src emacs-lisp :tangle "packages.el"
(package! typst-ts-mode :recipe (:host sourcehut :repo "meow_king/typst-ts-mode"
                             ;;:build (:not compile)
                             ))
#+end_src


#+begin_src emacs-lisp :tangle "config.el"
(use-package typst-ts-mode
  :custom
  ;; don't add "--open" if you'd like `watch` to be an error detector
  (typst-ts-mode-watch-options "--open")

  ;; experimental settings (I'm the main dev, so I enable these)
  (typst-ts-mode-enable-raw-blocks-highlight t)
  (typst-ts-mode-highlight-raw-blocks-at-startup t))
  #+end_src


** lsp-bridge :lsp:


#+begin_src emacs-lisp :tangle "packages.el"
(package! posframe)
(package! popon)
(package! lsp-bridge :recipe (:host github :repo "manateelazycat/lsp-bridge"
                              :files ("*")
                              :build (:not compile)
                              )
  )
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package lsp-bridge
  :init
  (setq lsp-bridge-flash-line-delay 1
        lsp-bridge-use-ds-pinyin-in-org-mode t
        acm-enable-tabnine-helper nil
        acm-enable-tabnine t
        acm-enable-copilot t
        acm-backend-copilot-node-path (concat doom-cache-dir "/.cache/copilot/bin/copilot-node-server")
        lsp-bridge-nix-lsp-server "nil"
        lsp-bridge-python-lsp-server "pylsp"
        lsp-bridge-python-command
         "/run/current-system/sw/bin/python")
  (setq lsp-bridge-org-babel-lang-list '("go" "python" "ipython"
                                         "ruby" "js" "css" "sass"
                                         "jupyter" "c" "rust" "java" "cpp" "jupyter-python"
                                         "c++" "sh"))
  :hook (doom-first-input . global-lsp-bridge-mode)
  :config
  (push '((nickel-mode nickel-ts-mode) . "nls") lsp-bridge-single-lang-server-mode-list)
  ;; (push '((nix-mode nix-ts-mode) . "rnix-lsp"
  ;;         )
  ;;       lsp-bridge-single-lang-server-mode-list)
  (push '((nix-mode nix-ts-mode) . "rnix-lsp")
      lsp-bridge-single-lang-server-mode-list)

  ;; (setq acm-candidate-match-function 'orderless-flex)
  )
;; (after! lsp-bridge
;;      (set-face-background 'acm-frame-default-face (face-attribute 'default :background))
;;       (set-face-background 'acm-frame-select-face (face-attribute 'highlight :background))
;;       (set-face-foreground 'acm-frame-select-face (face-attribute 'highlight :foreground))
;;         )
#+end_src

#+RESULTS:
| global-lsp-bridge-mode |


** lsp-acm :terminal:


#+begin_src emacs-lisp :tangle "packages.el"
(package! acm-terminal
  :recipe (:host github
           :repo "twlz0ne/acm-terminal"
           ))
#+end_src


#+begin_src emacs-lisp :tangle "config.el"
(unless (display-graphic-p)
  (after! acm
    (use-package acm-terminal
      )))
#+end_src

** nix-ts-mode

#+begin_src emacs-lisp :tangle "packages.el"
(package! nix-ts-mode
  :recipe (:host github
           :repo "remi-gelinas/nix-ts-mode"
           ))
#+end_src


#+begin_src emacs-lisp :tangle "config.el"
(use-package! nix-ts-mode
  :config
  (define-derived-mode nix-mode nix-ts-mode "Nix"
    "A major mode for Nix expressions.")
  (add-hook 'nix-ts-mode-hook #'lsp-bridge-mode)
  (add-hook 'nix-ts-mode-hook #'fingertip-mode)
  (add-to-list 'auto-mode-alist (cons "\\.nix\\'" 'nix-mode)))
#+end_src


** just

#+begin_src emacs-lisp :tangle "packages.el"
(package! justl
  :recipe (:host github
           :repo "psibi/justl.el"
           ))
(package! just-mode
  :recipe (:host github
           :repo "leon-barrett/just-mode.el"
           ))
#+end_src


#+begin_src emacs-lisp :tangle "config.el"
(use-package! just-mode)
(use-package! justl
  :config
  (setq justl-recipe-width 25))
#+end_src


** treesit


#+begin_src emacs-lisp :tangle "config.el"
(use-package! treesit
  :init
 ;;copyright: https://github.com/manateelazycat/lazycat-emacs/blob/master/site-lisp/config/init-treesit.el#L134
  (setq major-mode-remap-alist
        '((c-mode          . c-ts-mode)
          (c++-mode        . c++-ts-mode)
          (cmake-mode      . cmake-ts-mode)
          (conf-toml-mode  . toml-ts-mode)
          (css-mode        . css-ts-mode)
          (js-mode         . js-ts-mode)
          (js-json-mode    . json-ts-mode)
          (python-mode     . python-ts-mode)
          (sh-mode         . bash-ts-mode)
          (typescript-mode . typescript-ts-mode)
          (rust-mode       . rust-ts-mode)
          (java-mode       . java-ts-mode)
          ;;(nix-mode       .  nix-ts-mode)
          ))
  (add-hook 'markdown-mode-hook #'(lambda () (treesit-parser-create 'markdown)))

  (add-hook 'web-mode-hook #'(lambda ()
                             (let ((file-name (buffer-file-name)))
                               (when file-name
                                 (treesit-parser-create
                                  (pcase (file-name-extension file-name)
                                    ("vue" 'vue)
                                    ("html" 'html))))
                               )))

(add-hook 'emacs-lisp-mode-hook #'(lambda () (treesit-parser-create 'elisp)))
(add-hook 'ielm-mode-hook #'(lambda () (treesit-parser-create 'elisp)))
(add-hook 'json-mode-hook #'(lambda () (treesit-parser-create 'json)))
(add-hook 'go-mode-hook #'(lambda () (treesit-parser-create 'go)))
  )
#+end_src

#+RESULTS:
: treesit

*** treesit-auto

#+begin_src emacs-lisp :tangle "packages.el"
;;(package! treesit-auto)
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
;; (use-package! treesit-auto
;;   :config
;;   (global-treesit-auto-mode))
#+end_src


** nickel

#+begin_src emacs-lisp :tangle "packages.el"
(package! nickel-mode
  :recipe (;;:local-repo "~/ghq/github.com/GTrunSec/nickel-mode"
           :host github
           :repo "nickel-lang/nickel-mode"
           ))
#+end_src


#+begin_src emacs-lisp :tangle "config.el"
(use-package! nickel-mode
  :config
  (add-hook 'nickel-mode-hook #'electric-align-mode)
  (add-hook 'nickel-mode-hook #'lsp-bridge-mode)
  )
#+end_src


** Nushell

- [2022-12-12 Mon 11:14] -> https://github.com/azzamsa/emacs-nushell
- https://github.com/mrkkrp/nushell-mode

#+begin_src emacs-lisp :tangle "packages.el"
(package! nushell-mode :recipe (:host github :repo "mrkkrp/nushell-mode"
                                 :files ("*.el")
        ))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package! nushell-mode)
#+end_src


** graphviz-dot-mode :graphviz:
#+begin_src emacs-lisp :tangle "packages.el"
(package! graphviz-dot-mode :recipe (:host github :repo     "ppareit/graphviz-dot-mode"
                                 :files ("*.el")
        ))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package! graphviz-dot-mode)
#+end_src


* format-all

#+begin_src emacs-lisp :tangle "packages.el"
(package! format-all)
(package! language-id)
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package! format-all
  :config
 ;;(add-hook! 'format-all-mode-hook 'format-all-ensure-formatter)
 (prependq! format-all-default-formatters
            '(("Haskell" ormolu)
              ("Nix" alejandra)))
 )

#+end_src
* Meow
** default
#+begin_src emacs-lisp :tangle "config.el"
(defun meow-setup ()
  (setq meow-cheatsheet-layout meow-cheatsheet-layout-dvorak)
  (meow-leader-define-key
   '("1" . meow-digit-argument)
   '("2" . meow-digit-argument)
   '("3" . meow-digit-argument)
   '("4" . meow-digit-argument)
   '("5" . meow-digit-argument)
   '("6" . meow-digit-argument)
   '("7" . meow-digit-argument)
   '("8" . meow-digit-argument)
   '("9" . meow-digit-argument)
   '("0" . meow-digit-argument))
  (meow-normal-define-key
   '("0" . meow-expand-0)
   '("9" . meow-expand-9)
   '("8" . meow-expand-8)
   '("7" . meow-expand-7)
   '("6" . meow-expand-6)
   '("5" . meow-expand-5)
   '("4" . meow-expand-4)
   '("3" . meow-expand-3)
   '("2" . meow-expand-2)
   '("1" . meow-expand-1)
   '("-" . negative-argument)
   '(";" . meow-reverse)
   '("," . meow-inner-of-thing)
   '("." . meow-bounds-of-thing)
   '("<" . meow-beginning-of-thing)
   '(">" . meow-end-of-thing)
   '("a" . meow-append)
   '("A" . meow-open-below)
   '("b" . meow-back-word)
   '("B" . meow-back-symbol)
   '("c" . meow-change)
   '("C" . meow-change-save)
   '("d" . meow-delete)
   '("e" . meow-line)
   '("E" . meow-kmacro-lines)
   '("f" . meow-find)
   '("F" . meow-find-expand)
   '("g" . meow-keyboard-quit)
   '("G" . meow-goto-line)
   '("h" . meow-left)
   '("H" . meow-left-expand)
   '("i" . meow-insert)
   '("I" . meow-open-above)
   '("j" . meow-join)
   '("J" . delete-indentation)
   '("k" . meow-kill)
   '("l" . meow-till)
   '("L" . meow-till-expand)
   '("m" . meow-mark-word)
   '("M" . meow-mark-symbol)
   '("n" . meow-next)
   '("N" . meow-next-expand)
   '("o" . meow-block)
   '("O" . meow-block-expand)
   '("p" . meow-prev)
   '("P" . meow-prev-expand)
   '("q" . meow-quit)
   '("Q" . +popup/quit-window)
   '("r" . meow-replace)
   '("R" . meow-replace-save)
   '("s" . meow-search)
   '("S" . meow-pop-search)
   '("t" . meow-right-expand)
   '("u" . undo-fu-only-undo)
   '("U" . undo-fu-only-redo)
   '("v" . meow-visit)
   '("w" . meow-next-word)
   '("W" . meow-next-symbol)
   '("x" . meow-save)
   '("X" . meow-clipboard-save)
   '("y" . meow-yank)
   '("Y" . meow-clipboard-yank)
   '("z" . meow-pop-selection)
   '("&" . meow-query-replace)
   '("%" . meow-query-replace-regexp)
   '("<escape>" . meow-last-buffer))
  (meow-leader-define-key
   '("df" . fd-dired)
   '("rr" . consult-recent-file )
   '("da" . consult-ripgrep)
   '("SPC" . meow-M-x)
   '("ti" . insert-current-date-time-inactive)
   '("ta" . insert-current-date-time-active)
   '("tc" . insert-current-date-time)
   '("bs" . bookmark-set)
   '("bm" . bookmark-bmenu-list)
   '("bt" . bm-toggle)
   '("bb" . switch-to-buffer)
   '("bw" . +vertico/switch-workspace-buffer)

   ;; '("jr" . helm-register)
   ;; '("js" . point-to-register)
   '("?" . meow-cheatsheet)
   ))
#+end_src

#+RESULTS:
: meow-setup

** package
#+begin_src emacs-lisp :tangle "packages.el"
(package! meow :recipe (:host github :repo "DogLooksGood/meow"))
#+end_src

#+begin_src emacs-lisp :tangle "config.el"
(use-package meow
  :init
  (meow-global-mode 1)
  :custom
  (meow-esc-delay 0.001)
  :config
  (setq meow-keypad-leader-dispatch "C-c")
  (meow-setup-line-number)
  ;; If you need setup indicator, see `meow-indicator' for customizing by hand.
  (meow-setup-indicator)
  (setq meow-mode-state-list
        '((fundamental-mode . normal)
          (text-mode . normal)
          (prog-mode . normal)
          (conf-mode . normal)
          (eaf-mode . insert)))
  (meow-setup))
#+end_src

** keybinds

#+begin_src emacs-lisp :tangle "config.el"
(map! "C-s" #'+vertico/search-symbol-at-point
      "<f10>" #'blink-search
      "C-c p f" #'blink-search
      ;; (:prefix-map ("f" . "file")
      ;;  :desc "Search File" "f" #'consult-find
      ;;  )
      )
#+end_src

#+RESULTS:

* Tracking the pro configs
** [[https://tecosaur.github.io/emacs-config/#org-pkg-statement][Doom Emacs Configuration]] :doom:

