Skip to content

Latest commit

 

History

History
959 lines (904 loc) · 30 KB

config.org

File metadata and controls

959 lines (904 loc) · 30 KB

1 Global configuration

1.1 Custom functions

(defun highlight-changes-remove-after-save ()
  "Remove previous changes after save."
  (make-local-variable 'after-save-hook)
  (add-hook 'after-save-hook
	    (lambda ()
		(highlight-changes-remove-highlight (point-min) (point-max)))))

(defun toggle-alternative-input-method (method &optional arg interactive)
  (if arg
      (toggle-input-method arg interactive)
    (let ((previous-input-method current-input-method))
      (when current-input-method
        (deactivate-input-method))
      (unless (and previous-input-method
                   (string= previous-input-method method))
        (activate-input-method method)))))

(defun reload-alternative-input-methods ()
  (dolist (config alternative-input-methods)
    (let ((method (car config)))
      (global-set-key (cdr config)
                      `(lambda (&optional arg interactive)
                         ,(concat "Behaves similar to `toggle-input-method', but uses \""
                                  method "\" instead of `default-input-method'")
                         (interactive "P\np")
                         (toggle-alternative-input-method ,method arg interactive))))))

(defun show-file-name ()
  "Show the full path file name in the minibuffer."
  (interactive)
  (message (buffer-file-name)))


(defun sudo-edit (&optional arg)
  (interactive "P")
  (if (or arg (not buffer-file-name))
      (find-file (concat "/sudo:root@localhost:" (ido-read-file-name "File: ")))
    (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))

1.2 UI and behaviour setup

1.2.1 What to disable

(tooltip-mode      -1)
(menu-bar-mode     -1)
(tool-bar-mode     -1)
(scroll-bar-mode   -1)
(horizontal-scroll-bar-mode -1)
(blink-cursor-mode -1)
;; TAB indend is awefull
(setq-default indent-tabs-mode nil)

1.2.2 What to enable

Need to investigate what’s cool can I do with emacs server

(line-number-mode 1)
(column-number-mode 1)
(global-visual-line-mode 1) ;; auto breakline
(server-start) ;; enables emacsclient in console

1.2.3 Setup behaviour of new windows/bell/splash/…

(setq use-dialog-box     nil)
(setq redisplay-dont-pause t)
(setq pop-up-frames nil)
(setq ring-bell-function 'ignore)
(setq visible-bell t)
(setq inhibit-splash-screen t)
(setq inhibit-startup-message t)
(setq initial-scratch-message nil)
(setq scroll-preserve-screen-position t)
(setq switch-to-buffer-preserve-window-point t)
;; buffers split
(setq split-height-threshold nil)
(setq split-width-threshold 160)
;; file save property
(setq require-final-newline 't)
(setq create-lockfiles nil)
;; disable tabs indent
(setq indent-tabs-mode nil)

;; Tabs are part of Makefile so have to enable it
(add-hook 'makefile-mode-hook
          (lambda ()
            (setq-local indent-tabs-mode t)))

1.2.4 Scrolling

(setq scroll-step               1)
(setq scroll-margin            5)
(setq scroll-conservatively 10000)

1.2.5 Short messages

(defalias 'yes-or-no-p 'y-or-n-p)

1.2.6 Global clipboard

(setq x-select-enable-clipboard t)
(transient-mark-mode 1) ; highlight text selection
(delete-selection-mode 1) ; delete seleted text when typing

1.2.7 Input methods

(setq alternative-input-methods
      '(("ukrainian-computer" . [?\C-\\])
;        ("german-postfix"   . [?\C-\M-|])
))

(setq default-input-method
      (caar alternative-input-methods))

(reload-alternative-input-methods)

1.2.8 Custom theme

I prefer gruvbox-theme

;; (setq custom-safe-themes t)
(use-package gruvbox-theme
  :init
  (load-theme 'gruvbox-dark-medium t)) ;; We need to add t to trust this package

hint :: to list all fonts on system just use

fc-list :mono | awk -F: '{print $2}' | sort -u

Pick the desired font and tune the settings. By <2023-08-30 Wed> I use cormullion/juliamono font. Here are other pretty options: Iosevka, DejaVu Fonts.

;; (set-frame-font "Inconsolata 12" nil t)
(set-face-attribute 'default nil :font "Iosevka Fixed Medium Extended" :height 150)
;; (set-face-attribute 'default nil :font "JuliaMono Medium" :height 118)

1.2.9 WAIT Transparency

Not working though. I believe it’s problem with compiling emacs. True Emacs Transparency

(set-frame-parameter (selected-frame) 'alpha '(100 50))
(add-to-list 'default-frame-alist '(alpha 100 50))

1.2.10 Highlight changes

(global-highlight-changes-mode t)
(set-face-foreground 'highlight-changes nil)
(set-face-background 'highlight-changes "#382f2f")
(set-face-foreground 'highlight-changes-delete nil)
(set-face-background 'highlight-changes-delete "#916868")

;; This is not related to changes, but related to the flow. Let it be here for a bit
(add-hook 'before-save-hook 'delete-trailing-whitespace)
(add-hook 'after-save-hook 'highlight-changes-remove-after-save)

1.2.11 Save session

(desktop-save-mode 1)
(setq savehist-additional-variables
      '(kill-ring
        global-mark-ring
        search-ring
        regexp-search-ring
        file-name-history
        shell-command-history
        set-variable-value-history
        regexp-history
        compile-history
        w3m-input-url-history
        pyvenv-workon-history
        ))

1.2.12 Language & Encoding

Add UTF8 at the front of the priority list for automatic detection. Set up multilingual environment to use UTF-8. Set default value of various coding systems to UTF-8. Source

(prefer-coding-system 'utf-8)
(set-language-environment "UTF-8")
(set-default-coding-systems 'utf-8)

1.2.13 Global automated text manipulation

1.2.13.1 Auto close parenthesis globaly

(use-package elec-pair
  :ensure nil
  :hook (prog-mode . electric-pair-mode))

Automatically insert closing delimiter

(use-package syntactic-close
  :ensure t
  :bind ("C-c x c" . syntactic-close))
(use-package paren
  :ensure nil
  :init (setq show-paren-delay 0)
  :config (show-paren-mode +1))

1.2.13.2 Ligature symbols

Not sure if I want it. Need to setup font to handle ligatures tho disregard that, it has build in setup fonts command disregard this as well, I dont need it

;; (use-package fira-code-mode
;;   :custom (fira-code-mode-disabled-ligatures '("[]" "#{" "#(" "#_" "#_(" "x" "+")) ;; List of ligatures to turn off
;;   :hook prog-mode) ;; Enables fira-code-mode automatically for programming major modes

1.2.14 Autosave and backup files

EmacsWiki: Force Backups here’s a good guide. Meanwhile I’ll disable them

(setq make-backup-files nil)

1.2.15 Modeline

;; no

2 Modes

2.1 Management

Modes used mostly everywhere: interaction with version control, custom menues

2.1.1 Terminal

I was using multi-term along with helm-mt for ages. But Author suggests aweshell - a multi-term featured eshell. I need to give it a look one day

(use-package multi-term
  :bind
  ( "C-!" . (lambda ()
    	      (interactive)
    	      (funcall #'multi-term-dedicated-open)
    	      (funcall #'multi-term-dedicated-select))
    :custom
    (multi-term-program "/bin/zsh"))

  ;; Disabling yas here
  (add-hook 'term-mode-hook (lambda()
                              (yas-minor-mode -1)))

  ;; Load shell variables to emacs
  (use-package exec-path-from-shell
    :ensure t
    :config
    (setq exec-path-from-shell-check-startup-files nil)
    ;; http://stackoverflow.com/questions/35286203/exec-path-from-shell-message-when-starting-emacs
    (when (string= system-type "gnu/linux")
      (exec-path-from-shell-initialize)))

  (use-package helm-mt
    :after multi-term)

2.1.2 Version control

Magit is the only option here :)

(use-package magit
  ;; :init
  ;; (message "Loading Magit!")
  ;; :config
  ;; (message "Loaded Magit!")
  ;; :bind (("C-x g" . magit-status)
  ;;        ("C-x C-g" . magit-status))
  )

2.1.3 DONE Autocompletion

Here will be company, I believe. Comment it out and set up propperly later. source

(use-package company
  :bind (:map company-active-map
              ("C-n" . 'company-select-next)
              ("C-p" . 'company-select-previous))
  :init
  (global-company-mode t)
  :config
  (setq company-minimum-prefix-length 3)
  (setq company-idle-delay 0))

2.1.4 Rainbow Delimiters

(use-package rainbow-delimiters
  :config
  (progn
    ;; Enable in all programming-related modes
    (add-hook 'prog-mode-hook #'rainbow-delimiters-mode)))

2.1.5 Helm

The UI framework I stick to Used some code from here.

(use-package helm
  :diminish
  :config
  ;; https://github.com/syl20bnr/spacemacs/issues/13564
  ;; another useful command is (delete-dups extended-command-history)
  (setq history-delete-duplicates t)
  (when (executable-find "curl")
    (setq helm-google-suggest-use-curl-p t))
  (add-to-list 'helm-sources-using-default-as-input 'helm-source-info-bash)
  (helm-mode 1)
  (helm-autoresize-mode 1)
  :custom
  ;; See https://github.com/bbatsov/prelude/pull/670 for a detailed
  ;; discussion of these options.
  (helm-split-window-in-side-p t)
  (helm-M-x-fuzzy-match t)
  (helm-recentf-fuzzy-match t)
  (helm-semantic-fuzzy-match t)
  (helm-imenu-fuzzy-match t)
  (helm-move-to-line-cycle-in-source t)
  (helm-ff-search-library-in-sexp t)
  (helm-ff-file-name-history-use-recentf t)
  (helm-commands-using-frame '(completion-at-point
                               helm-apropos
                               helm-eshell-prompts
                               helm-imenu
                               helm-imenu-in-all-buffers))

  :bind
    (("M-x"     . helm-M-x) ;; Evaluate functions
     ("C-x C-f" . helm-find-files) ;; Open or create files
     ("C-x b"   . helm-mini) ;; Select buffers
     ("C-x C-b" . helm-buffers-list) ;; Select buffers
     ("C-x C-r" . helm-recentf) ;; Select recently saved files
     ("C-c i"   . helm-imenu) ;; Select document heading
     ("M-y"     . helm-show-kill-ring) ;; Show the kill ring
     ("M-i"     . helm-swoop)  ;; Swoop
     ("C-x M-i" . helm-multi-swoop-all)  ;; Swoop
     ("C-c M-i" . helm-multi-swoop-projectile)  ;; Swoop
     :map helm-map
     ("C-z" . helm-select-action)
     ("<tab>" . helm-execute-persistent-action)))

(use-package helm-ag
  :after helm
  :custom
  (helm-ag-base-command "ag --nocolor --nogroup --ignore-case")
  (helm-ag-command-option "--all-text")
  (helm-ag-insert-at-point 'symbol)
  (helm-ag-use-grep-ignore-list t))

(use-package helm-swoop
  :after helm
  :custom
  (help-swoop-pattern "")
  (helm-swoop-use-line-number-face t)
  :bind
  ("M-i" . helm-swoop))

2.1.6 Projectile

Project management framework

(use-package projectile
  ;; :init
  ;; (setq projectile-cache-file (concat live-tmp-dir "projectile-cache"))
  ;; (setq projectile-known-projects-file (concat live-tmp-dir "projectile-known-projects.eld"))
  :delight '(:eval (concat "" (projectile-project-name)))
  :config
  ;; Pretty standard to have this setup, setting it globally
  (projectile-update-project-type 'clojure-cli
                                  :test-dir "test/"
                                  :src-dir "src/")
  (projectile-register-project-type 'yarn '("yarn-lock.json")
                                    :compile "yarn install"
                                    :test "yarn test"
                                    :run "yarn start")
  (projectile-register-project-type 'npm '("npm-lock.json")
                                    :compile "npm ci"
                                    :test "npm test"
                                    :run "npm run")
  (setq projectile-globally-ignored-directories
        (append '("node_modules") projectile-globally-ignored-directories))

  :custom
  (projectile-mode-line-prefix " P:")
  (projectile-idle-timer-seconds 60)
  (projectile-indexing-method 'alien)
  (projectile-enable-caching t)
  (projectile-switch-project-action 'projectile-dired)
  (projectile-remember-window-configs t )
  (projectile-completion-system 'helm)
  (projectile-switch-project-action 'helm-projectile)
  :bind-keymap
  ("C-c p" . projectile-command-map))

;; (use-package persp-projectile
;;   :after (projectile perspective))

(projectile-global-mode)

2.1.6.1 helm-pojectile

Helm menues

(use-package helm-projectile
  :after helm
  :config
  (helm-projectile-on))

2.1.7 TODO Dired

GitHub - alexluigit/dirvish: A polished Dired with batteries included.

2.1.8 Yasnippet

(use-package yasnippet
  :hook ((web-mode . yas-minor-mode)
         (ts-mode . yas-minor-mode)
         (org-mode . yas-minor-mode))
  :config
  (yas-reload-all))

2.1.9 IN-PROGRESS Flycheck

(use-package flycheck
  :ensure t
  :init
  (progn
    ;; (global-flycheck-mode)
    ;;(add-hook 'flycheck-mode-hook 'my/use-eslint-from-node-modules)
    ))

2.1.10 Flyspell

Spellcheck

(use-package flyspell
  :ensure t
  :defer t
  :init
  (add-hook 'text-mode-hook 'flyspell-mode)
  (add-hook 'prog-mode-hook 'flyspell-prog-mode)
  )

2.1.11 Tramp

;;disable backups of files edited with tramp
;; (add-to-list 'bkup-backup-directory-info
;;              (list tramp-file-name-regexp ""))
(setq tramp-bkup-backup-directory-info  nil)

(setq tramp-ssh-controlmaster-options
      "-o ControlMaster=auto -o ControlPath='tramp.%%C' -o ControlPersist=no -o ConnectTimeout=1")

;; Pick SSH system agent
(exec-path-from-shell-copy-env "SSH_AGENT_PID")
(exec-path-from-shell-copy-env "SSH_AUTH_SOCK")

2.1.12 TODO REST client

source

(use-package restclient
  :ensure t
  :init
  ;; limit number of times vars are substituted
  (setq restclient-vars-max-passes 2)
  ;; use matching client certificates from ~/.authinfo
  (setq network-stream-use-client-certificates t)
  :mode
  ("\\.restclient\\'" . restclient-mode)
  ("\\.rest\\'" . restclient-mode)
  ("\\.http\\'" . restclient-mode)

  :custom
  (restclient-content-type-modes
   '(("application/json" . json-mode)
     ("application/x-yaml" . yaml-mode)
     ("application/xml" . nxml-mode)
     ("application/yaml" . yaml-mode)
     ("image/gif" . image-mode)
     ("image/jpeg" . image-mode)
     ("image/jpg" . image-mode)
     ("image/png" . image-mode)
     ("text/html" . web-mode)
     ("text/plain" . text-mode)
     ("text/xml" . nxml-mode)
     ("text/yaml" . yaml-mode))))

(use-package restclient-helm
  :after restclient)

(use-package company-restclient
  :after restclient
  :ensure t
  :config
  )

(add-to-list 'company-backends 'company-restclient)
(use-package ob-restclient)

2.1.13 TODO Language Server

2.1.14 Docker integration

Dokcer is a part of everyday life now. I’ve seen an integration in VSCode and I liked it. Trying to achieve something alike in emacs.

(use-package docker
  :ensure t
  :bind ("C-c d" . docker))
(use-package dockerfile-mode
  :ensure t)

(use-package docker-compose-mode
  :ensure t)

2.2 Web development

2.2.1 Typescript server

Disabled additional modes, like company, for this listing. But better be enabled later.

(use-package tide
  :ensure t
  :after (typescript-mode) ;;(typescript-mode company flycheck)
  :hook ((typescript-mode . tide-setup)
         (typescript-mode . tide-hl-identifier-mode)
         (before-save . tide-format-before-save))
  :bind (:map web-mode-map
         ("C-c j" . tide-jsdoc-template)
         :map typescript-mode-map
         ("C-c j" . tide-jsdoc-template))
  :config
  (progn
    ;; (flycheck-mode +1)
    (setq flycheck-check-syntax-automatically '(save mode-enabled))))
    ;; (eldoc-mode +1)
    ;; tide-hl-identifier-mode +1)
    ;; company is an optional dependency. You have to
    ;; install it separately via package-install
    ;; `M-x package-install [ret] company`
    ;; (company-mode +1))

2.2.2 Svelte

Svelte uses slightly modified JS, but it can interoperate with web-mode

(use-package svelte-mode
  :defer t
  :ensure t
  :mode "\\.svelte\\'")

2.2.3 JSONs

(use-package json-mode
  :ensure t
  :mode
  ("\\.\\(json\\)$" . json-mode)
  :custom
  (js-indent-level 2))

2.2.4 YAML

(use-package yaml-mode
  :mode ("\\.\\(yml\\|yaml\\|\\config\\|sls\\)$" . yaml-mode)
  :ensure yaml-mode
  :defer t)

2.2.5 Graphql

(use-package graphql-mode
  :ensure t
  :mode "\\.graphql\\'")

2.2.6 Web mode

My favorite mode for the web-development

(use-package web-mode
  :ensure t
  :mode "\\.\\(phtml\\|php\\|[gj]sp\\|as[cp]x\\|erb\\|djhtml\\|html?\\|hbs\\|ejs\\|jade\\|swig\\|tm?pl\\|vue\\|js\\|jsx\\|tsx\\|svelte\\)$"
  :custom
  (web-mode-code-indent-offset 2)
  (web-mode-markup-indent-offset 2)
  (web-mode-css-indent-offset 2)
  (web-mode-enable-current-element-highlight t)
  ;; this magic incantation fixes highlighting of jsx syntax in .js files
  (web-mode-content-types-alist
   '(
     ("jsx" . "\\.js[x]?\\'")
     ("tsx" . "\\.ts[x]?\\'")))
  (web-mode-engines-alist
   '(
     ("svelte" . "\\.svelte\\'")
     ("tide". "\\.\\(ts\\|tsx\\)")))
  :config
  ;; (progn
  ;;   (add-hook 'web-mode-hook ;; todo move to hooks
  ;;             (lambda ()
  ;;               (when (string-equal "tsx" (file-name-extension buffer-file-name))
  ;;                 (setup-tide-mode))
  ;;               (when (string-equal "jsx" (file-name-extension buffer-file-name))
  ;;                 (setup-tide-mode))
  ;;               (when (string-equal "js" (file-name-extension buffer-file-name))
  ;;                 (progn
  ;;                   (setup-tide-mode)
  ;;                   (with-eval-after-load 'flycheck
  ;;                     (flycheck-add-mode 'typescript-tslint 'web-mode)
  ;;                     (flycheck-add-mode 'javascript-tide 'web-mode))))
  ;;               (company-mode)
  ;;               (emmet-mode)
  ;;               (rainbow-delimiters-mode)
  ;;               ;; (prettier-js-mode)
  ;;               )))
  )

2.2.7 Prettier

;; Format HTML, CSS and JavaScript/JSON
;; Install: npm -g install prettier
(when (executable-find "prettier")
  (use-package prettier
    :diminish
    :hook ((js-mode js2-mode css-mode sgml-mode web-mode) . prettier-mode)
    :init (setq prettier-pre-warm 'none)))

2.2.8 Nginx config

(use-package nginx-mode)

2.3 Org-mode and zettelcasten

To process this config on startup, org-mode is initialized in =./init.el=. Here I’ll setup additional components, like org-roam

2.3.1 Org-modern styles

Spotted this package and decided to try

(use-package org-modern
  :after org-roam
  ;; :custom
  ;; (org-modern-priority nil)
  ;(org-modern-hide-stars nil)
  :hook
  (org-mode . org-modern-mode)
  (org-agenda-finalize . org-modern-agenda))

2.3.2 Babel

Main babel setup

(use-package ob
  :ensure nil
  :after org
  :config
  (setq org-export-use-babel nil
        org-confirm-babel-evaluate nil)
  (org-babel-do-load-languages
   'org-babel-load-languages
   '((emacs-lisp . t)
     (python . t)
     (clojure . t)
     (C . t)
     (typescript .t)
     (dot . t)
     (python .t)
     (shell . t)
     (scheme . t)
     (js . t)
     )))

2.3.2.1 Python

(use-package ob-python
  :ensure nil
  :after (ob python)
  :config
  (setq org-babel-python-command python-shell-interpreter))

2.3.2.2 Typescript

(use-package ob-typescript
  :ensure t
  :requires typescript-mode
  :after org
  :config
  (org-babel-do-load-languages 'org-babel-load-languages
			       (append org-babel-load-languages
				       '((typescript . t)))))

2.3.3 org-cliplink

Yanks a link, using html>head>title as description

(use-package org-cliplink
  :after org
  :bind
  ("C-c i" . 'org-cliplink))

2.3.4 IN-PROGRESS org yank images

Absolute TODO, I’d like to yank images from clipboard and image is to be stored in certain directory (i believe something like ./files/%buffername% for ztl)

(use-package org-download
  :after org
  :demand t

  :commands (org-download-enable
             org-download-yank
             org-download-screenshot)

  :config
  (setq org-startup-with-inline-images t)
  (setq org-download-display-inline-images t)
  (setq org-download-method 'attach)
  (setq org-download-file-format-function #'identity)
  (setq-default org-download-image-dir
              (file-name-as-directory
               (concat "./files/"
                       (file-name-base (or buffer-file-name ""))
                       "/")))
  (defun org-download-annotate-default (link)
      "Annotate LINK with the time of download."
      (make-string 0 ?\s))
  ;; (setq org-download-screenshot-method "screencapture -i %s")

  :hook ((org-mode dired-mode) . org-download-enable))

2.3.5 helm-org

Helm menues for org actions

(use-package helm-org
  :after org
  :config (progn
            (setq helm-org-headings-fontify t))
  :bind
  ("C-c o" . 'helm-org-in-buffer-headings))

2.3.6 Zettelcasten

Let’s set the zettel dir explicitly

(setq ztl-directory org-directory)
(setq ztl-exp-dir "~/src/zettel.online")
;; This have to be global for org-roam-id-smth command at least
(setq org-roam-directory (file-truename ztl-directory))

2.3.6.1 org-roam

Org-roam - the “engine” for zettelcasten

(use-package org-roam
    :after org
    :init (setq org-roam-v2-ack t) ;; Acknowledge V2 upgrade
    :custom
    ;;(org-roam-directory (file-truename ztl-directory))
    (org-roam-complete-everywhere t)
    :config
    (setq org-roam-capture-templates
          '(("d" "default" plain "%?"
             :if-new (file+head "${slug}.org"
                                "#+OPTIONS: timestamp:t title:t toc:nil todo:t |:t\n#+TITLE: ${title}\n#+DATE: %T\n")
             :unnarrowed t)))
    (setq org-roam-mode-sections
      '((org-roam-backlinks-section :unique t)
        org-roam-reflinks-section))
    (defun org-roam-custom-link-builder (node)
      (let ((file (org-roam-node-file node)))
        (concat (file-name-base file) ".html")))
    (setq org-roam-graph-link-builder 'org-roam-custom-link-builder)

    (org-roam-setup)
    :bind (("C-c n f" . org-roam-node-find)
           ("C-c n R" . org-roam-node-random)
           (:map org-mode-map
                 (("C-c n i" . org-roam-node-insert)
                  ("C-c n o" . org-id-get-create)
                  ("C-c n t" . org-roam-tag-add)
                  ("C-c n a" . org-roam-alias-add)
                  ("C-c n l" . org-roam-buffer-toggle)
                  ("C-c n r" . org-roam-ref-add)
                  ("C-c n <Tab>" . completion-at-point)))))

2.3.6.2 org-roam-ui

And org-roam-ui - fancy web interface for roam with a nice graph.

(use-package org-roam-ui
    :after org-roam
;;         normally we'd recommend hooking orui after org-roam, but since org-roam does not have
;;         a hookable mode anymore, you're advised to pick something yourself
;;         if you don't care about startup time, use
;;  :hook (after-init . org-roam-ui-mode)
    :config
    (setq org-roam-ui-sync-theme t
          org-roam-ui-follow t
          org-roam-ui-update-on-save t
          org-roam-ui-open-on-start nil))

2.3.6.3 deft

Deft - alternative “scanner” through ztl directory. Not needed anymore. Disable hotkey

(use-package deft
  ;; :bind ("C-c d" . deft)		;
  :commands (deft)
  :config (setq deft-directory ztl-directory
                deft-extensions '("txt" "org")
                deft-recursive t
                deft-strip-summary-regexp
                (concat
                 "\\("
	         "^:.+:.*\n" ; any line with a :SOMETHING:
	         "\\|^#\\+.*\n" ; anyline starting with a #+
	         "\\|^\\*.+.*\n" ; anyline where an asterisk starts the line
	         "\\)")))

(advice-add 'deft-parse-title :override
    (lambda (file contents)
      (if deft-use-filename-as-title
	  (deft-base-filename file)
	(let* ((case-fold-search 't)
	       (begin (string-match "title: " contents))
	       (end-of-begin (match-end 0))
	       (end (string-match "\n" contents begin)))
	  (if begin
	      (substring contents end-of-begin end)
	    (format "%s" file))))))

2.3.7 IN-PROGRESS Org export configurations

General publishing configuration. It’s a huge TODO. One day I’ll enable zettelcasten to autoexport

(use-package ox-publish
  :ensure org
  :after (org)
  :config
  (message "ztl-directory is set to: %s" ztl-directory)
  (setq org-publish-project-alist
        `(
          ("org-notes"
           :base-directory ,ztl-directory
           :base-extension "org"
           :publishing-directory ,ztl-exp-dir
           :section-numbers nil
           :with-creator nil
           :recursive t
           :publishing-function org-html-publish-to-html
           :headline-levels 5             ; Just the default for this project.
           :auto-preamble t
           :auto-sitemap t                ; Generate sitemap.org automagically...
           :sitemap-filename "sitemap.org"  ; ... call it sitemap.org (it's the default)...
           :sitemap-title ""         ; ... with title 'Sitemap'.

           :html-wrap-src-lines t

           )
          ("org-static"
           :base-directory ,ztl-directory
           :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf"
           :publishing-directory ,ztl-exp-dir
           :recursive t
           :publishing-function org-publish-attachment
           )
          ("org" :components ("org-notes" "org-static"))
          ))

  )

;; Gemini mode
(use-package ox-gemini
  :after org
  :init (add-to-list 'org-export-backends 'gemini)))

;; (use-package ox-mediawiki
;;   :after org)

;; Dependent on `:publishing-function ` of `ox-publish`
(use-package ox-wk
  :after org)

2.4 Other usefull modes

2.4.1 Markdown and github

(use-package markdown-mode
  :ensure t
  :commands (markdown-mode gfm-mode)
  :mode (("README\\.md\\'" . gfm-mode))
  ;; optional external md->html converter. maybe i'll use pandoc some day
  ;; :init (setq markdown-command "/usr/local/bin/multimarkdown")
  )
(use-package ox-gfm
  :init (add-to-list 'org-export-backends 'gfm))

2.4.2 SCAD mode

(use-package scad-mode
  :ensure t
  :mode "\\.scad\\'"
  :hook (scad-preview-mode . (lambda ()
                               (local-set-key (kbd "C-<left>") 'scad-preview-translate-y+)
                               (local-set-key (kbd "C-<right>") 'scad-preview-translate-y-)
                               (local-set-key (kbd "C-<down>") 'scad-preview-rotate-y+)
                               (local-set-key (kbd "C-<up>") 'scad-preview-rotate-y-)))
  :custom
  (scad-preview-colorscheme "Gruvbox")
  (scad-preview-size '(1900 . 1900))
  (scad-preview-camera '(0 0 0 50 0 20 100))
  )

2.5 Embedded development

2.5.1 TODO Rust

(use-package rust-mode)
(use-package cargo
  :hook (rust-mode . cargo-minor-mode))

2.5.2 Platformio

(use-package platformio-mode
  :custom
  (platformio-mode-keymap-prefix (kbd "C-c p"))
  :hook
  (c++-mode . platformio-conditionally-enable))

2.5.3 TODO C++

Lots of todos

2.5.3.1 CMake

3 Global keys

Should be mostly moved to :bind

;; -- Window manipulation
(global-set-key (kbd "S-C-<left>") 'shrink-window-horizontally)
(global-set-key (kbd "S-C-<right>") 'enlarge-window-horizontally)
(global-set-key (kbd "S-C-<down>") 'shrink-window)
(global-set-key (kbd "S-C-<up>") 'enlarge-window)

;; -- X-clipboard
(global-set-key (kbd "C-M-y") 'x-clipboard-yank)

;; -- Multi-term needs
(global-set-key (kbd "C-c M-o") 'comint-clear-buffer)
(global-set-key (kbd "C-x t t") 'helm-mt)

;; -- Custom help maps
(define-key help-map "\M-f" 'show-file-name)