init.el

Documenting my init.el :- will annotate soon, just dumping as of now

(require 'server)
(unless (server-running-p)
  (server-start))

(set-frame-font "CaskaydiaCove NF" nil t)

;;no, thank you
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)

                                        ;ERROR handling

(setq byte-compile-warnings '(cl-functions))
(setq ring-bell-function 'ignore)
(setq visible-bell t)


                                        ;BOOTSTRAPPING STRAIGHT.EL (defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

(straight-use-package 'use-package)
(setq straight-path "~/.emacs.d/straight/")


                                        ;GENERAL + binding free ups

(use-package general
  :straight t
  :config
  (general-unbind
    "C-M-o" ; free up for org-roam *Notes*
    "C-M-r" ; free up for remote ops))
    "C-s" ; for super bindings))
    ))


                                        ;DASHBOARD

(use-package dashboard
  :straight t
  :config
  (dashboard-setup-startup-hook)
  (general-define-key
   "C-c h" (lambda () (interactive)(view-buffer "*dashboard*")))
  (setq
   initial-buffer-choice (lambda () (get-buffer "*dashboard*"))
   dashboard-center-content t
   dashboard-startup-banner 'logo
   ))

                                        ;EVIL ENV

(use-package evil
  :straight t
  :init
  (use-package undo-fu
    :straight t
    :config
    (general-define-key
     :states 'normal
     "u" #'undo-fu-only-undo
     "\C-r" #'undo-fu-only-redo)
    (setq evil-undo-system 'undo-fu))
  (setq
   evil-want-keybinding nil
   evil-want-integration t)
  :config 
  (evil-mode 1))


(use-package evil-collection
  :straight t
  :after evil
  :config
  (evil-collection-init))

(use-package evil-org
  :straight t
  :after org
  :config
  (general-add-hook 'org-mode
                    (list #'evil-org-mode))
  (require 'evil-org-agenda)
  (evil-org-agenda-set-keys))


(use-package evil-surround
  :straight t
  :config
  (global-evil-surround-mode 1))

                                        ;HELM

(use-package helm
  :straight t
  :config
  (general-define-key
   "M-x" #'helm-M-x
   "C-h a" #'helm-apropos
   "C-/" #'helm-occur
   "C-x C-f" #'helm-find-files)
  (helm-mode 1))

                                        ;PROJECTILE
(use-package projectile
  :init
  :straight t
  :config
  (projectile-mode 1)
  (use-package helm-projectile
    :straight t
    :config
    (general-define-key
     :prefix "C-c p"
     "f f" #'helm-projectile-find-file
     "f d" #'helm-projectile-find-dir
     "a" #'helm-projectile-ack)))


                                        ;FILE MANAGEMENT : DIRED-X

(setq find-file-visit-truename t)
(general-add-hook 'dired-load-hook
                  (list (lambda ()
                          (load "dired-x")
                          ;; Set dired-x global variables here.  For example:
                          ;; (setq dired-guess-shell-gnutar "gtar")
                          ;; (setq dired-x-hands-off-my-keys nil)
                          )))

                                        ;AESTHETICS

(use-package doom-themes
  :straight t)
(use-package darkroom
  :straight t)
(use-package nimbus-theme
  :straight t
  :config
  (load-theme 'nimbus t))
(use-package beacon
  :straight t
  :init
  (setq beacon-size 60 
        beacon-blink-when-focused t
        beacon-blink-when-point-moves-vertically 5
        beacon-blink-when-window-changes t
        beacon-color "#4444bb"
        beacon-blink-delay 0.2
        beacon-blink-duration 0.2)
  :config
  (beacon-mode 1))

                                        ;MODELINE AND ICONS
;;(use-package mini-modeline
;;  :straight t
;;  :init
;;  (mini-modeline-mode t))

(use-package doom-modeline
  :straight t
  :init
  (use-package all-the-icons :straight t)
  (use-package minions :straight t)
  :config
  (setq doom-modeline-height 30)
  (setq doom-modeline-bar-width 3)
  (setq doom-modeline-window-width-limit fill-column)
  (setq doom-modeline-icon (display-graphic-p))
  (setq doom-modeline-major-mode-icon t)
  (setq doom-modeline-continuous-word-count-modes '(org-mode))
  (setq doom-modeline-modal-icon t)
  (setq doom-modeline-mu4e t)
  (setq doom-modeline-minor-modes (featurep 'minions))
  (general-add-hook 'after-init-hook
                    (list #'doom-modeline-mode
                          #'minions-mode)))


(use-package nlinum-relative
  :straight t
  :config
  (nlinum-relative-setup-evil)                    
  (general-add-hook 'prog-mode-hook
                    (list #'nlinum-relative-mode))
  (setq nlinum-relative-redisplay-delay 0)      
  (setq nlinum-relative-current-symbol "->")      
  (setq nlinum-relative-offset 0)) 

                                        ;QUICK CONFIG

(defun edit-init ()
  (interactive)
  (message (concat "editing user-init-file @ " user-init-file))
  (find-file user-init-file))

(defun open-scratch-space ()
  (interactive)
  (message (concat "opening scratch space @ /mnt/c/Users/Raj Patil/source/scratch" ))
  (find-file "/mnt/c/Users/Raj Patil/source/scratch"))

(general-define-key
 :prefix "C-c"
 "e" #'edit-init
 "s" #'open-scratch-space)

                                        ;Window management

(use-package window-purpose
  :straight t
  :config
  ;;(add-to-list 'purpose-user-mode-purposes '(<major-mode> . <purpose>))
  ;;(add-to-list 'purpose-user-name-purposes '(<name> . <purpose>))
  ;;(add-to-list 'purpose-user-regexp-purposes '(<pattern> . <purpose>))
  ;;(purpose-compile-user-configuration))
  ;;(purpose-mode 1))
  (purpose-compile-user-configuration)
  (general-define-key
   :prefix "C-c ,"
   "d" #'(lambda ()
           (interactive)
           (message "dedicating current window")
           (set-window-dedicated-p (selected-window) t))
   "u" #'(lambda ()
           (interactive)
           (message "undedicating current window")
           (set-window-dedicated-p (selected-window) nil))))

                                        ;Tabs
(use-package eyebrowse
  :straight t
  :config
  (eyebrowse-mode t))

                                        ;buffer managment
(general-define-key "C-c i" #'ibuffer)


                                        ;WHICH-KEY

(use-package which-key
  :straight t
  :config
  (which-key-mode)
  (general-define-key "C-h C-k" #'which-key-show-top-level)
  (which-key-setup-side-window-bottom))

                                        ;BROWSING

(setq browse-url-browser-function 'eww-browse-url)
(setq shr-max-image-proportion 0.6)
(general-define-key
 "C-c C-e C-c" #'eww-copy-page-url
 "C-c t" #'toggle-truncate-lines)

                                        ;PDF INTEROP

(use-package pdf-tools
  :straight (pdf-tools :host github
                       :repo "vedang/pdf-tools")
  :config
  (pdf-loader-install))


                                        ;MAGIT

(use-package magit :straight t)

                                        ;ORG-OPS

(put 'narrow-to-region 'disabled nil)
(use-package org
  :straight t
  :config
  (general-define-key
   :prefix "C-c"
   "l" #'org-store-link
   "a" #'org-agenda
   "c" #'org-capture
   "!" #'org-time-stamp-inactive)
  (setq org-directory (file-truename "~/source/org/")
        org-default-notes-file (concat org-directory "/gtd/GTD_HQ.org")
        org-startup-with-inline-images t
        org-startup-truncated nil)
  (general-add-hook 'org-mode-hook
                    (list #'toggle-word-wrap
                          #'flyspell-mode
                          #'nlinum-relative-mode))
  (defun update-org-latex-fragments ()
    (org-latex-preview '(64))
    (plist-put org-format-latex-options :scale (* 2 text-scale-mode-amount))
    (org-latex-preview '(16)))
  (general-add-hook 'text-scale-mode-hook
                    (list #'update-org-latex-fragments))
  (setq org-latex-packages-alist '(("margin=2cm" "geometry")))
  (setq org-clock-persist 'history)
  (org-clock-persistence-insinuate)
  (general-define-key
   :prefix "C-c"
   "r" #'org-refile
   "C-x C-g" #'org-clock-goto))

                                        ;ORG-BABEL
;;(org-babel-do-load-languages
;; 'org-babel-load-languages
;; '((python . t)))
;;(mermaid . t)))

                                        ;(setq org-babel-python-command "/home/rajp152k/miniconda3/bin/python")

;;(use-package ob-mermaid
;;  :straight t
;;  :config
;;  (setq ob-mermaid-cli-path "/home/rajp152k/node_modules/.bin/mmdc"))

(use-package org-bullets
  :straight t
  :config
  (general-add-hook
   'org-mode-hook (lambda () (org-bullets-mode 1))))

(defun +org/opened-buffer-files ()
  "Return the list of files currently opened in emacs"
  (delq nil
        (mapcar (lambda (x)
                  (if (and (buffer-file-name x)
                           (string-match "\\.org$"
                                         (buffer-file-name x)))
                      (buffer-file-name x)))
                (buffer-list))))

(setq org-refile-targets '((+org/opened-buffer-files :maxlevel . 5)))

(setq org-capture-templates
      '(("n" "Next Action" entry (file+headline "~/links/source/org/gtd/GTD_HQ.org" "NA")
         "* TODO %?\n  %i\n  %a")
        ("e" "Event" entry (file+headline "~/links/source/org/gtd/GTD_HQ.org" "Events")
         "* %?\nSCHEDULED: %T\n  %i")
        ("i" "IN" entry (file+headline "~/links/source/org/gtd/GTD_HQ.org" "INQ")
         "* %?\nEntered on %U\n  %i\n  %a")
        ("c" "consolidate" entry (file+headline "~/links/source/org/gtd/GTD_HQ.org" "Consolidate")
         "* %?\nEntered on %U\n  %i\n  %a")
        ("t" "Tickler" entry (file+headline "~/links/source/org/gtd/GTD_HQ.org" "Tickler")
         "* %?\nDEFER THOUGHT TO: %T\n %i"))) 

                                        ;GTD

(defun gtd()
  "open the GTD workspace"
  (interactive)
  (let ((gtd-dir (concat org-directory "/gtd/GTD_HQ.org")))
    (message (concat "opening GTD workspace @ " gtd-dir))
    (find-file gtd-dir)
    (flyspell-mode-off)))

(general-define-key
 :prefix "C-c"
 "g" #'gtd)

                                        ;ORG-AI




                                        ;ORG-ROAM

(use-package org-roam
  :straight (org-roam :host github
                      :repo "org-roam/org-roam")
  :config
  (setq org-id-method 'ts)
  (setq org-roam-directory (file-truename "/mnt/c/Users/Raj Patil/source/org/braindump/Content/"))
  (setq org-roam-file-extensions '("org"))
  (org-roam-db-autosync-mode)
  (defun org-roam-tag-list ()
    (interactive)
    (let ((tag-list (org-roam-db-query
                     [:select :distinct [tag]
                              :from tags])))
      (switch-to-buffer "*scratch*")
      (dolist (tag tag-list)
        (insert (concat (car tag) "\n")))))
  (general-define-key
   :prefix "C-M-o"
   "f" #'org-roam-node-find
   "i" #'org-roam-node-insert
   "c" #'org-roam-capture
   "h" #'(lambda ()
           (interactive)
           (find-file (concat org-roam-directory "index.org")))
   "d s" #'org-roam-db-sync
   "t a" #'org-roam-tag-add
   "t d" #'org-roam-tag-remove
   "t l" #'org-roam-tag-list
   "r" #'org-roam-buffer-toggle
   "o c" #'org-id-get-create
   "o s" #'org-id-store-link
   "a a" #'org-roam-alias-add
   "a d" #'org-roam-alias-remove)
  (add-to-list 'display-buffer-alist
               '(; org-roam buffer toggle config
                 (".org-roam.*"
                  (display-buffer-in-side-window)
                  (window-width . 0.25)
                  (side . left)
                  (slot 0)))))

(use-package websocket
  :straight t
  :after org-roam)

(use-package org-roam-ui
  :straight (:host github
                   :repo "org-roam/org-roam-ui"
                   :files ("*.el" "out"))
  :after org-roam
  :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 t))

                                        ;COMPANY

(use-package company
  :straight t
  :config
  (setq company-idle-delay 0.2)
  (setq company-minimum-prefix-length 2)
  (add-to-list 'company-backends 'company-capf)
  (setq company-ignore-case t)
  (global-company-mode 1))

(use-package company-box
  :straight t
  :config
  (general-add-hook 'company-mode-hook
                    (list 'company-box-mode)))

(use-package company-lsp
  :straight t
  :requires company
  :config
  (push 'company-lsp company-backends)
  ;;disable client side cache as LSP does is better
  (setq company-transformers nil
        company-lsp-async t
        company-lsp-cache-candidates nil))

                                        ;PYTHON
;;(use-package pyvenv
;;  :straight t
;;  :config
;;  (setenv "WORKON_HOME" "/home/rajp152k/miniconda3/envs/")
;;  (pyvenv-mode 1)
;;  (pyvenv-workon "emacs"))

;;(when (executable-find "ipython")
;;  (setq python-shell-interpreter "ipython"))

                                        ;YAML
(use-package yaml-mode
  :straight t
  :config
  (add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode)))




                                        ; LSP

;;(use-package lsp-mode
;;  :straight t
;;  :config
;;  (setq lsp-prefer-flymake nil)
;;  (general-define-key "C-M-l" (general-simulate-key "s-l")) ;; no super key
;;  (general-add-hook
;;   (list 'c++-mode-hook
;;       'python-mode-hook
;;       'racket-mode-hook)
;;   (list #'lsp))
;;  (general-add-hook
;;   'lsp-mode-hook
;;   (list #'lsp-enable-which-key-integration))
;;  (setq lsp-clients-clangd-args '("-j=4" "-background-index" )
;;      lsp-clients-clangd-executable "clangd"))
;;
;;;;c++ compile_flags.txt auto place
;;
;;(defun clangd-lsp-setup ()
;;  (interactive)
;;  ;;check if database already exists
;;  (let* ((dir default-directory)
;;       (include-path-1 "/usr/include/c++/")
;;       (include-path-2 "/usr/include/x86_64-linux-gnu/c++/")
;;       (ver (caddr (directory-files include-path-1)))
;;       (includes-str (concat "-I" (concat include-path-1 ver) "/\n"
;;                             "-I" (concat include-path-2 ver) "/\n"))
;;       (compilation-db (concat dir "compile_flags.txt")))
;;    (if (file-exists-p compilation-db)
;;      (message "compilation database already exists")
;;      (progn (message "placing a new compilation database")
;;           (write-region includes-str nil compilation-db)))))
;;
;;(general-add-hook 'c++-mode-hook
;;                (list#'clangd-lsp-setup))

;;(use-package lsp-pyright
;;  :straight t
;;  :config
;;  (general-add-hook 'python-mode #'(lambda () (lsp)) ))

;;(use-package lsp-racket
;;  :straight 'lsp-racket)
;;:type git
;;:host github
;;:repo "mullikine/lsp-racket-el"))

;;(use-package dap-mode
;;  :straight t)
;;
;;(use-package lsp-ui
;;  :straight t
;;  :requires lsp-mode flycheck
;;  :config
;;  (setq lsp-ui-doc-enable t
;;      lsp-ui-doc-use-childframe t
;;      lsp-ui-doc-position 'top
;;      lsp-ui-doc-include-signature t
;;      lsp-ui-sidline-enable t
;;      lsp-ui-flycheck-list-position 'right
;;      lsp-ui-flycheck-live-reporting t
;;      lsp-ui-peek-enable t
;;      lsp-ui-peek-list-width 60
;;      lsp-ui-peek-peek-height 40)
;;  (general-add-hook 'lsp-mode-hook (list 'lsp-ui-mode)))

                                        ; remote ops

;;(defun remote-shell-specifics ()
;;  (when (and (fboundp 'company-mode)
;;           (file-remote-p default-directory))
;;    (company-mode -1)))
;;(general-add-hook 'shell-mode-hook #'remote-shell-specifics)

                                        ;LISP ADD ONS

(use-package smartparens
  :straight t
  :config
  (smartparens-global-mode t))

(use-package rainbow-delimiters
  :straight t
  :config
  (general-add-hook #'lisp-mode-hook
                    '(rainbow-delimiters-mode-enable)))


                                        ;SLIME
(use-package slime
  :straight t
  :config
  (setq inferior-lisp-program "sbcl"))


                                        ;RACKET

;;(use-package racket-mode
;;  :straight t
;;  :config
;;  (setq racket-documentation-search-location 'local
;;      racket-images-inline t)
;;  (general-add-hook (list 'racket-mode-hook 'racket-repl-mode-hook)
;;                  (list #'rainbow-delimiters-mode)))


                                        ;ELISP

(general-add-hook 'emacs-lisp-mode-hook
                  (list 'smartparens-mode ;;use (kbd `C-q '`) for single quoting
                        'rainbow-delimiters-mode))

                                        ;BLOG

(use-package easy-hugo
  :straight t
  :config
  (setq easy-hugo-basedir "/mnt/c/Users/Raj Patil/source/thebitmage.com/")
  (setq easy-hugo-url "https://thebitmage.com")
  (setq easy-hugo-root "/usr/local/bin")
  (defun blog ()
    "Open blogging workspace"
    (interactive)
    (let ((blog-dir "~/links/source/thebitmage.com"))
      (message (concat "opening blogging workspace @ " blog-dir))
      (find-file blog-dir)))
  (defun life-hex-count ()
    "number of days I've been alive"
    (interactive)
    (let* ((birth (date-to-time "2000-05-01 19:30 IST"))
           (today (date-to-time (format-time-string "%Y-%m-%d %H:%M:%S %Z" (current-time)) ))
           (diff (float-time (time-subtract today birth))))
      (insert (format "0x%X" (/ diff 86400)))))
  (defun hex-ops ()
    "hexify decimal number at point, invoke life hex at count if nil"
    (interactive)
    (defun delete-word-at-point ()
      (kill-word 1)
      (backward-kill-word 1))
    (defun valid-number-p (str)
      "Check if a string is a valid number."
      (string-match-p "^[+-]?[0-9]*\\.?[0-9]+\\(?:[eE][+-]?[0-9]+\\)?$" str))
    (let ((dec-days (word-at-point)))
      (cond ((null dec-days) (life-hex-count))
            ((valid-number-p dec-days) (progn
                                         (delete-word-at-point)
                                         (insert (format " 0x%X " (string-to-number dec-days)))) )
            (t (message "invalid request; ignoring ...")))))
  (general-define-key
   :prefix "C-c C-h"
   "b" #'easy-hugo-newpost
   "C-b" #'blog
   "C-t" #'hex-ops))



                                        ;DICTIONARY
(use-package define-word
  :straight t
  :config
  (general-define-key
   :prefix "C-c"
   "d" #'define-word-at-point
   "D" #'define-word))

                                        ;LATEX

;;install auctex from package-list-packages
;;don't use the github mirror via straight
;;(setq TeX-auto-save t
;;      TeX-parse-self t
;;      TeX-view-program-selection '((output-pdf "PDF Tools"))
;;      TeX-source-correlate-start-server t)
;;(general-add-hook 'TeX-after-compilation-finished-functions
;;                #'TeX-revert-document-buffer)
;;
;;(setq-default TeX-master nil)
;;(general-add-hook 'Latex-mode-hook
;;                (list #'LaTeX-math-mode
;;                      #'turn-on-reftex
;;                      #'flyspell-mode))
;;
                                        ;MARKDOWN

(use-package markdown-mode
  :straight t
  :config 
  (set-fill-column 40)
  (general-add-hook 'markdown-mode-hook
                    (list #'nlinum-relative-mode
                          #'auto-fill-mode
                          #'flyspell-mode)))

Tags::emacs: