Skip to content

Latest commit

 

History

History
637 lines (570 loc) · 18.8 KB

config.org

File metadata and controls

637 lines (570 loc) · 18.8 KB

Add files

(add-to-list 'load-path "~/.emacs.d/lisp/")

Better defaults

Simple Settings

;;Defaults
(tool-bar-mode -1)
(menu-bar-mode -1)
(scroll-bar-mode -1)
(setq inhibit-startup-message t)
(setq make-backup-files nil)
(setq auto-save-default nil)
(setq scroll-conservatively 100)
(defalias 'yes-or-no-p 'y-or-n-p)
(global-subword-mode 1)
(setq confirm-kill-emacs 'y-or-n-p)
;; Line highlighting
(when window-system (global-hl-line-mode t))
;; Enable line number in prog mode
(add-hook 'prog-mode-hook 'display-line-numbers-mode)
;; Column indicator
(add-hook 'prog-mode 'display-fill-column-indicator-mode)
(add-hook 'go-mode 'display-fill-column-indicator-mode)
;; GNU style indentation
(setq c-default-style "linux"
      c-basic-offset 4)
;; IBuffer default
(setq ibuffer-expert t)
;; Frame opacity
(set-frame-parameter nil 'alpha-background 90)
;; (add-to-list 'default-frame-alist '(alpha-background . 100))
;; Run aliases in shell-command
(setq shell-command-switch "-ic")

Config Reload

;; Reload config file
(defun config-reload ()
  "Reloads ~/.emacs.d/config.org at runtime"
  (interactive)
  (org-babel-load-file (expand-file-name "~/.emacs.d/config.org")))

Recenter frame

(defun frame-center ()
  "Center the current frame."
  (interactive)
  (let* ((dw (display-pixel-width))
         (dh (display-pixel-height))
         (f  (selected-frame))
         (fw (frame-pixel-width f))
         (fh (frame-pixel-height f))
         (x  (- (/ dw 2) (/ fw 2)))
         (y  (- (/ dh 2) (/ fh 2))))
    (message (format "dw %d dh %d fw %d fh %d x %d y %d" dw dh fw fh x y))
    (set-frame-position f x y)))
(run-with-idle-timer 0 nil #'frame-center)

Package

Convenience

Sudo edit

(use-package sudo-edit
  :ensure t
  :bind ("s-e" . sudo-edit))

Which-key

(use-package which-key
  :ensure t
  :init
  (which-key-mode 1))

Open in external app

(use-package openwith
  :ensure t
  :config
  (openwith-mode t)
  (setq openwith-associations
        '(("\\.pdf\\'" "zathura" (file))
          ("\\.epub\\'" "zathura" (file))
          ("\\.mkv\\'" "mpv" (file)))))

Tools

xah-fly-keys

init and settings

;; init
(require 'xah-fly-keys)
(require 'xah-fly-keys-org)
(xah-fly-keys-set-layout "colemak-dh")
(setq xah-fly-use-meta-key nil)
(xah-fly-keys 1)
;; Custom settingt
(global-set-key (kbd "<escape>") 'xah-fly-command-mode-activate)
(defun xah-insert-angle-bracket () (interactive) (xah-insert-bracket-pair "<" ">"))
(defun xah-insert-asterics () (interactive) (xah-insert-bracket-pair "*" "*" ))
(define-key xah-fly-leader-key-map (kbd "s 8") 'xah-insert-asterics)
(define-key xah-fly-leader-key-map (kbd "i 9") 'async-shell-command)
(define-key xah-fly-leader-key-map (kbd "i s") 'magit)
(define-key xah-fly-leader-key-map (kbd "i r") 'config-reload)

Escape key

(progn
  (defun xah-fly-keys-escape ()
    (interactive)
    (when (region-active-p)
      (deactivate-mark))
    (when (active-minibuffer-window)
      (abort-recursive-edit)))

  (define-key xah-fly-command-map (kbd "<escape>")     'xah-fly-keys-escape))

(progn
  (defvar xah-fly-keys-fast-keyseq-timeout 200)

  (defun xah-fly-keys-tty-ESC-filter (map)
    (if (and (equal (this-single-command-keys) [?\e])
             (sit-for (/ xah-fly-keys-fast-keyseq-timeout 1000.0)))
        [escape] map))

  (defun xah-fly-keys-lookup-key (map key)
    (catch 'found
      (map-keymap (lambda (k b) (if (equal key k) (throw 'found b))) map)))

  (defun xah-fly-keys-catch-tty-ESC ()
    "Setup key mappings of current terminal to turn a tty's ESC into
`escape'."
    (when (memq (terminal-live-p (frame-terminal)) '(t pc))
      (let ((esc-binding (xah-fly-keys-lookup-key input-decode-map ?\e)))
        (define-key input-decode-map
          [?\e] `(menu-item "" ,esc-binding :filter xah-fly-keys-tty-ESC-filter)))))

  (xah-fly-keys-catch-tty-ESC)

  (define-key key-translation-map (kbd "ESC") (kbd "<escape>")))

Latex

(use-package auctex
  :ensure t
  :defer t
  :hook (LaTeX-mode .
                    (lambda ()
                      (push (list 'output-pdf "Zathura")
                            TeX-view-program-selection))))

Ssh

(use-package ssh
  :ensure t)
(add-hook 'ssh-mode-hook
          (lambda ()
            (setq ssh-directory-tracking-mode t)
            (shell-dirtrack-mode t)
            (setq dirtrackp nil)))

Visual

Olivetti

(use-package olivetti
  :defer t
  :ensure t
  :custom
  (olivetti-body-width 95)
)

Rainbow

(use-package rainbow-mode
  :ensure t
  :bind
  ("s-h" . rainbow-mode))

Rainbow-delimiters

(use-package rainbow-delimiters
  :ensure t
  :init
  (rainbow-delimiters-mode 1))

Mode line

(use-package doom-modeline
  :ensure t
  :init
  (doom-modeline-mode 1)
  (setq doom-modeline-major-mode-color-icon nil)
  (setq doom-modeline-buffer-encoding nil)
  (setq doom-modeline-minor-modes nil)
  (setq doom-modeline-modal nil)
  (setq line-number-mode nil))

Icons

(use-package all-the-icons
  :if (display-graphic-p))
(use-package all-the-icons-dired
  :ensure t
  :hook (dired-mode . all-the-icons-dired-mode))
(use-package all-the-icons-ibuffer
  :ensure t
  :init
  (setq all-the-icons-ibuffer-color-icon nil)
  (setq all-the-icons-ibuffer-human-readable-size t)
  :hook (ibuffer-mode . all-the-icons-ibuffer-mode))

Dired

(setq dired-listing-switches "-alhv")  ; -a to include hidden files, -l for long format, -h for human-readable sizes
;; Sort
(defun xah-dired-sort ()
  (interactive)
  (let (xsortBy xarg)
    (setq xsortBy (completing-read "Sort by: " '( "date" "size" "name" )))
    (cond
     ((equal xsortBy "name") (setq xarg "-Alhv "))
     ((equal xsortBy "date") (setq xarg "-Alh -t"))
     ((equal xsortBy "size") (setq xarg "-Alh -S"))
     ((equal xsortBy "dir") (setq xarg "-Al --group-directories-first"))
     (t (error "logic error 09535" )))
    (dired-sort-other xarg )))
(require 'dired )
(define-key dired-mode-map (kbd "s") 'xah-dired-sort)

Programmig

Magit

(use-package magit
  :ensure t)

Comipilation

(require 'ansi-color)
(defun colorize-compilation-buffer ()
  "Apply ANSI color codes in the *compilation* buffer."
  (let ((inhibit-read-only t))
    (ansi-color-apply-on-region (point-min) (point-max))))
(add-hook 'compilation-filter-hook 'colorize-compilation-buffer)

(use-package recompile-on-save
  :ensure t)
(recompile-on-save-advice compile)
;; (use-package smart-compile
;;   :ensure t
;;   :bind
;;   ("C-u" . smart-compile))

Language server protocol

(use-package lsp-mode
  :ensure t
  :bind (:map lsp-mode-map
              ("C-c d" . lsp-describe-thing-at-point)
              ("C-c j" . lsp-find-definition))
  :config
  (lsp-enable-which-key-integration t))

(setq lsp-modeline-code-actions-enable nil)

Fly-check

(use-package flycheck
  :ensure t)

Completions

(use-package company
  :ensure t
  :config
  (company-tng-configure-default)
  (setq company-idle-delay 0.1
        company-minimum-prefix-lenght 1))

Prog modes

Golang mode

(use-package go-mode
  :ensure t
  :hook ((go-mode . lsp-deferred)
         (go-mode . company-mode))
  :bind (:map go-mode-map
              ("<f5>" . gofmt))
  :config
  (require 'lsp-go)
  ;; GOPATH/bin
  (add-to-list 'exec-path "~/Programming/golang/bin")
  ;; add imports
  (setq gofmt-command "goimports"))

;; Format(fmt) file on save
(add-hook 'go-mode-hook
          (lambda ()
            (add-hook 'before-save-hook 'gofmt-before-save nil t)))

Lua mode

(use-package lua-mode
             :ensure t)

Org mode

GTD workflow

 (setq org-directory "~/Documents/org")
 (setq org-agenda-files (list "inbox.org" "agenda.org" "projects.org"))
 (define-key global-map (kbd "C-c c") 'org-capture)
 (define-key global-map (kbd "C-c a") 'org-agenda)

 ;; Capture templates
 (setq org-capture-templates
	`(("i" "Inbox" entry  (file "inbox.org")
	   ,(concat "* TODO %?\n"
		    "/Entered on/ %U"))
	  ("m" "Meeting" entry  (file+headline "agenda.org" "Future")
	   ,(concat "* %?\n"
		    "<%<%Y-%m-%d %a %H:00>>"))))

 ;; Capture "Inbox" entry right way "C-c i"
 (defun org-capture-inbox ()
   (interactive)
   (call-interactively 'org-store-link)
   (org-capture nil "i"))
 (define-key global-map (kbd "C-c i") 'org-capture-inbox)

 ;; Refile from inbox to projects
 (setq org-refile-targets
	'(("projects.org" :regexp . "\\(?:\\(?:Note\\|Task\\)s\\)")))
 (setq org-refile-use-outline-path 'file)
 (setq org-outline-path-complete-in-steps nil)

 ;; Add key words
 (setq org-todo-keywords
	'((sequence "TODO(t)" "NEXT(n)" "HOLD(h)" "|" "DONE(d)")))

 ;; Add timestamp when changed to NEXT
 (defun log-todo-next-creation-date (&rest ignore)
   "Log NEXT creation time in the property drawer under the key 'ACTIVATED'"
   (when (and (string= (org-get-todo-state) "NEXT")
	       (not (org-entry-get nil "ACTIVATED")))
     (org-entry-put nil "ACTIVATED" (format-time-string "[%Y-%m-%d]"))))
 (add-hook 'org-after-todo-state-change-hook #'log-todo-next-creation-date)

 ;; Estimate time to complete a task
 (setq org-log-done 'time)

 ;; Hide tag and filename in aganda view
 (setq org-agenda-hide-tags-regexp ".")
 (setq org-agenda-prefix-format
	'((agenda . " %i %-12:c%?-12t% s")
	  (todo   . " ")
	  (tags   . " %i %-12:c")
	  (search . " %i %-12:c")))

 ;; Customi agenda view
 (setq org-agenda-custom-commands
	'(("g" "Get Things Done (GTD)"
	   ((agenda ""
		    ((org-agenda-skip-function
		      '(org-agenda-skip-entry-if 'deadline))
		     (org-deadline-warning-days 0)))
	    (todo "NEXT"
		  ((org-agenda-skip-function
		    '(org-agenda-skip-entry-if 'deadline))
		   (org-agenda-prefix-format "  %i %-12:c [%e] ")
		   (org-agenda-overriding-header "\nTasks\n")))
	    (agenda nil
		    ((org-agenda-entry-types '(:deadline))
		     (org-agenda-format-date "")
		     (org-deadline-warning-days 7)
		     (org-agenda-skip-function
		      '(org-agenda-skip-entry-if 'notregexp "\\* NEXT"))
		     (org-agenda-overriding-header "\nDeadlines")))
	    (tags-todo "inbox"
		       ((org-agenda-prefix-format "  %?-12t% s")
			(org-agenda-overriding-header "\nInbox\n")))
	    (tags "CLOSED>=\"<today>\""
		  ((org-agenda-overriding-header "\nCompleted today\n")))))))

 ;; Save files after org-capture
 (setq org-agenda-files
	(mapcar 'file-truename
		(file-expand-wildcards "~/Documents/org/*.org")))
 ;; Save the corresponding buffers
 (defun gtd-save-org-buffers ()
   "Save `org-agenda-files' buffers without user confirmation.
 See also `org-save-all-org-buffers'"
   (interactive)
   (message "Saving org-agenda-files buffers...")
   (save-some-buffers t (lambda ()
			   (when (member (buffer-file-name) org-agenda-files)
			     t)))
   (message "Saving org-agenda-files buffers... done"))
 ;; Add it after refile
 (advice-add 'org-refile :after
	      (lambda (&rest _)
		(gtd-save-org-buffers)))

 ;; Change from TODO to DONE when all children are done.
 (defun org-summary-todo (n-done n-not-done)
   (let (org-log-done org-todo-log-states)   ; turn off logging
     (org-todo (if (= n-not-done 0) "DONE" "TODO"))))
 (add-hook 'org-after-todo-statistics-hook #'org-summary-todo)

 ;; Olivetti-mode
 (add-hook 'org-mode-hook 'olivetti-mode)
 (add-hook 'org-agenda-mode-hook 'olivetti-mode)

 ;; Use the whole window
 (add-hook 'org-capture-mode-hook 'delete-other-windows)
 (add-hook 'org-agenda-mode-hook 'delete-other-windows)

Settings

(setq org-src-window-setup 'current-window)
(setq org-hide-emphasis-markers t)
;; (add-hook 'org-mode-hook 'org-indent-mode)
(setq org-structure-template-alist
      '(("el" . "src emacs-lisp\n")))

Org-superstar

(use-package org-superstar
  :ensure t
  :config
  (add-hook 'org-mode-hook (lambda () (org-superstar-mode 1))))

Theme

(set-frame-font "Iosevka Comfy 10" nil t)
;; Disable borders from left and right
(set-fringe-mode 0)
(use-package modus-themes
  :ensure t
  :config
  ;; Operandi tinted
  (setq modus-operandi-tinted-palette-overrides
        ;; Remove the border
        '((border-mode-line-active unspecified)
          (border-mode-line-inactive unspecified)
          ;; Small changes
          (bg-hl-line bg-dim)
          (cursor fg-ochre)
          (bg-tab-bar bg-main)
          (bg-tab-current bg-active)
          (bg-tab-other bg-dim)
          (comment yellow-faint)))

  ;; Vivendi palette
  (setq modus-vivendi-palette-overrides
        '( ;; Base Colors
          ;; (fg-main "#cccccc")
          ;; (comment "#333333")
          (red             "#d88b88")
          (red-warmer      "#d89484")
          (red-cooler      "#d89aa2")
          (red-faint       "#d8a6a0")
          (red-intense     "#d87f7f")
          (green           "#7fb77f")
          (green-warmer    "#9eaf6f")
          (green-cooler    "#6fbb94")
          (green-faint     "#97c5a8")
          (green-intense   "#7fc77f")
          (yellow          "#c2af6f")
          (yellow-warmer   "#d8b675")
          (yellow-cooler   "#c2a07f")
          (yellow-faint    "#c2b08a")
          (yellow-intense  "#dbd273")
          (blue            "#6f98c2")
          (blue-warmer     "#8a9bc2")
          (blue-cooler     "#6fabc2")
          (blue-faint      "#8fb3c2")
          (blue-intense    "#6f86c2")
          (magenta         "#c29ab7")
          (magenta-warmer  "#c28fb2")
          (magenta-cooler  "#a697c2")
          (magenta-faint   "#b39dc2")
          (magenta-intense "#c27fc2")
          (cyan            "#7fb7b2")
          (cyan-warmer     "#90c2c2")
          (cyan-cooler     "#9ac2af")
          (cyan-faint      "#a6c2c0")
          (cyan-intense    "#7fc7c2")

          ;; Difs
          (bg-added           "#1f3228")
          (bg-added-faint     "#17251e")
          (bg-added-refine    "#2a4035")
          (bg-added-fringe    "#385245")
          (fg-added           "#8a9f94")
          (fg-added-intense   "#748e7e")
          (bg-changed         "#35341e")
          (bg-changed-faint   "#2b2a16")
          (bg-changed-refine  "#474a39")
          (bg-changed-fringe  "#5d5b4b")
          (fg-changed         "#b1a88c")
          (fg-changed-intense "#a4937a")
          (bg-removed         "#4a2a2f")
          (bg-removed-faint   "#3b2324")
          (bg-removed-refine  "#5c3a3e")
          (bg-removed-fringe  "#704c52")
          (fg-removed         "#c8a6a6")
          (fg-removed-intense "#b79b9b")
          (bg-diff-context    "#1f1f1f")

          ;; ModeLine
          (bg-mode-line-active "#090909")
          (fg-mode-line-active "#909090")
          (bg-mode-line-inactive "#000000")
          (fg-mode-line-inactive "#555555")

          ;; Remove borders
          (border-mode-line-active unspecified)
          (border-mode-line-inactive unspecified)

          ;; Line number
          (bg-line-number-inactive "#090909")
          (bg-line-number-active "#090909")
          (fg-line-number-inactive "#333333")
          (fg-line-number-active "#999999")

          ;; Selected text
          ;; Darker
          ;; (bg-region "#111111")
          ;; (fg-region "#292929")
          ;; Lighter
          (bg-region "#181818")
          (fg-region "#aaaaaa")

          ;; Search
          (bg-search-current "#3d4589")
          (bg-search-lazy "#1f2344")

          ;; Dired
          (bg-mark-select "#090909")
          (fg-mark-select "#252a54")

          ;; Paren
          (bg-paren-match "#5e50af")
          (fg-paren-match "#aaaaaa")

          ;; Org mode Code Blocks
          (bg-hover-secondary "#050505")
          (bg-prose-block-delimiter "#0a0a0a")
          (bg-prose-block-contents "#0a0a0a")

          ;; Current line
          (bg-hl-line "#090909"))))

(load-theme 'modus-vivendi)
(enable-theme 'modus-vivendi)

;; (load-theme 'modus-vivendi-tinted)
;; (enable-theme 'modus-vivendi-tinted)

;; (load-theme 'modus-operandi-tinted)
;; (enable-theme 'modus-operandi-tinted)

Web

(use-package shr
  :ensure nil
  :defer t
  :config
  (setq shr-use-colors nil)             ; t is bad for accessibility
  (setq shr-use-fonts nil)              ; t is not for me
  (setq shr-max-image-proportion 0.6)
  (setq shr-image-animate nil)          ; No GIFs, thank you!
  (setq shr-width fill-column)          ; check `prot-eww-readable'
  (setq shr-max-width fill-column)
  (setq shr-discard-aria-hidden t)
  (setq shr-fill-text nil)              ; Emacs 31
  (setq shr-cookie-policy nil))

(use-package eww
  :ensure nil
  :commands (eww)
  :hook (eww-mode . olivetti-mode)
  :config
  ;; (setq eww-restore-desktop t)
  (setq eww-desktop-remove-duplicates t)
  (setq eww-header-line-format nil)
  (setq eww-search-prefix "https://duckduckgo.com/html/?q=")
  (setq eww-download-directory (expand-file-name "~/Documents/eww-downloads"))
  (setq eww-suggest-uris
        '(eww-links-at-point
          thing-at-point-url-at-point))
  (setq eww-bookmarks-directory (locate-user-emacs-file "eww-bookmarks/"))
  (setq eww-history-limit 150)
  (setq eww-use-external-browser-for-content-type
        "\\`\\(video/\\|audio\\)") ; On GNU/Linux check your mimeapps.list
  (setq eww-browse-url-new-window-is-tab nil)
  (setq eww-form-checkbox-selected-symbol "[X]")
  (setq eww-form-checkbox-symbol "[ ]")
  (setq eww-retrieve-command nil))

;; Prot extensions
(provide 'prot-eww)
(setq prot-eww-save-history-file
      (locate-user-emacs-file "prot-eww-visited-history"))
(setq prot-eww-save-visited-history t)
(setq prot-eww-bookmark-link nil)

(add-hook 'prot-eww-history-mode-hook #'hl-line-mode)