summaryrefslogtreecommitdiff
path: root/emacs/init.el
diff options
context:
space:
mode:
Diffstat (limited to 'emacs/init.el')
-rw-r--r--emacs/init.el426
1 files changed, 426 insertions, 0 deletions
diff --git a/emacs/init.el b/emacs/init.el
new file mode 100644
index 0000000..ffd53f6
--- /dev/null
+++ b/emacs/init.el
@@ -0,0 +1,426 @@
+;;; package --- init.el
+;;; Comentary:
+
+;; A new init.el
+
+;;; Code:
+
+(with-eval-after-load 'package
+ (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t))
+
+;; Automatic reread from disk if the underlying file changes
+(setq auto-revert-interval 1)
+(setq auto-revert-check-vc-info t)
+(global-auto-revert-mode)
+
+;; Move thourgh windows with Ctrl-<arrow keys>
+(windmove-default-keybindings 'meta)
+
+;; Fix archaic defaults
+(setq sentence-end-double-space nil)
+
+;; Make right click do something sensible
+(when (display-graphic-p)
+ (context-menu-mode))
+
+
+;; Tramp - Faster than default scp
+(setq tramp-default-method "ssh")
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;
+;;; Interface enhancements/defaults
+;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; Mode line information
+(setq line-number-mode t) ; Show current line in modeline
+(setq column-number-mode t) ; Show column as well
+
+(setq x-underline-at-descent-line nil) ; Prettier underlines
+(setq switch-to-buffer-obey-display-actions t) ; Make switching buffers more consistent
+
+(setq-default show-trailing-whitespace nil) ; By default, don't underline trailing spaces
+(setq-default indicate-buffer-boundaries nil) ; Show buffer top and bottom in the margin
+
+;; Misc. UI tweaks
+(blink-cursor-mode -1) ; Steady cursor
+(pixel-scroll-precision-mode) ; Smooth scrolling
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;
+;;; Tab-bar configuration
+;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; Show the tab-bar as soon as tab-bar functions are invoked
+(setq tab-bar-show 0)
+
+;; Add the time to the tab-bar, if visible
+(add-to-list 'tab-bar-format 'tab-bar-format-align-right 'append)
+(add-to-list 'tab-bar-format 'tab-bar-format-global 'append)
+(setq display-time-format "%a %F %T")
+(setq display-time-interval 1)
+(display-time-mode)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;
+;;; Theme
+;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(use-package emacs
+ :config
+ (if (display-graphic-p)
+ (progn
+ (load-theme 'modus-operandi)
+ (set-face-attribute 'default nil :font "Fantasque Sans Mono" :height 110)
+ (set-face-attribute 'fixed-pitch nil :font "Input Mono" :height 100)
+ (set-face-attribute 'variable-pitch nil :font "IBM Plex Sans" :height 110)
+ (setq modus-themes-operandi-color-overrides
+ '((bg-main . "#fefcf4"))))
+ (load-theme 'gruvbox-dark-hard)))
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;
+;;; Org
+;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(setq org-agenda-files (list "~/OrgRoam/agenda.org"
+ "/home/work/OrgRoam/20230808170239-code_reviews.org"
+ "/home/work/OrgRoam/20230808173230-tareas.org"))
+
+(use-package org
+ :hook ((org-mode . visual-line-mode) ; wrap lines at word breaks
+ (org-mode . flyspell-mode)) ; spell checking!
+
+ :bind (:map global-map
+ ("C-c l s" . org-store-link) ; Mnemonic: link → store
+ ("C-c l i" . org-insert-link-global) ; Mnemonic: link → insert
+ ("C-c a" . org-agenda))
+ :config
+ (require 'org-tempo) ; Abbrv support for code blocks
+ (add-to-list 'org-export-backends 'md)
+
+ ;; Make org-open-at-point follow file links in the same window
+ (setf (cdr (assoc 'file org-link-frame-setup)) 'find-file)
+
+ ;; Make exporting quotes better
+ (setq org-export-with-smart-quotes t)
+ (setq org-confirm-babel-evaluate nil) ; Dont prompt for evaluation
+ )
+(add-hook 'org-mode-hook (lambda ()
+ (auto-fill-mode)
+ (variable-pitch-mode)
+ (bug-reference-mode)
+ (olivetti-mode)
+ (olivetti-set-width 100)))
+(use-package org-roam
+ :ensure t
+ :defer t
+ :init (setq org-roam-v2-ack t)
+ :custom
+ (org-roam-directory "~/OrgRoam")
+ :bind (("C-c n l" . org-roam-buffer-toggle)
+ ("C-c n f" . org-roam-node-find)
+ ("C-c n i" . org-roam-node-insert))
+ :config
+ ;; (org-roam-setup) ;; One shot?
+ (org-roam-db-autosync-mode)
+ (setq org-roam-index-file "~/OrgRoam/index.org")
+ (add-to-list 'display-buffer-alist
+ '("\\*org-roam\\*"
+ (display-buffer-in-side-window)
+ (side . right)
+ (window-width . 0.4)
+ (window-height . fit-window-to-buffer))))
+
+(use-package org-jira
+ :config (setq jiralib-url "https://comprandoengrupo.atlassian.net"))
+
+(use-package org-modern
+ :ensure t
+ :init (global-org-modern-mode))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;
+;;; Minibuffer and completion
+;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; Vertico: better vertical completion for minibuffer commands
+(use-package vertico
+ :ensure t
+ :init
+ ;; You'll want to make sure that e.g. fido-mode isn't enabled
+ (vertico-mode))
+
+;; Marginalia: annotations for minibuffer
+(use-package marginalia
+ :ensure t
+ :config
+ (marginalia-mode))
+
+(use-package corfu
+ :ensure t
+ :custom
+ (corfu-cycle t)
+ :bind
+ (:map corfu-map
+ ("SPC" . corfu-insert-separator))
+ :hook ((prog-mode . corfu-mode)
+ (shell-mode . corfu-mode)
+ (eshell-mode . corfu-mode))
+ :init (global-corfu-mode))
+
+;; Part of corfu
+(use-package corfu-popupinfo
+ :after corfu
+ :hook (corfu-mode . corfu-popupinfo-mode)
+ :custom
+ (corfu-popupinfo-delay '(0.25 . 0.1))
+ (corfu-popupinfo-hide nil)
+ :config
+ (corfu-popupinfo-mode))
+
+;; Make corfu popup come up in terminal overlay
+(use-package corfu-terminal
+ :if (not (display-graphic-p))
+ :ensure t
+ :config
+ (corfu-terminal-mode))
+
+;; Pretty icons for corfu
+(use-package kind-icon
+ :if (display-graphic-p)
+ :ensure t
+ :after corfu
+ :config
+ (add-to-list 'corfu-margin-formatters #'kind-icon-margin-formatter))
+
+;; Orderless: powerful completion style
+(use-package orderless
+ :ensure t
+ :config
+ (setq completion-styles '(orderless)))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;
+;;; Packages
+;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; Treesiter config
+
+(use-package emacs
+ :config
+ ;; Treesitter config
+
+ ;; Tell Emacs to prefer the treesitter mode
+ ;; You'll want to run the command `M-x treesit-install-language-grammar' before editing.
+ (setq major-mode-remap-alist
+ '(;(yaml-mode . yaml-ts-mode)
+ (bash-mode . bash-ts-mode)
+ (js2-mode . js-ts-mode)
+ (typescript-mode . typescript-ts-mode)
+ (json-mode . json-ts-mode)
+ (css-mode . css-ts-mode)
+ (python-mode . python-ts-mode)))
+ :hook
+ ;; Auto parenthesis matching
+ ((prog-mode . electric-pair-mode)))
+
+;; Eglot
+(use-package eglot
+ ;; no :ensure t here because it's built-in
+
+ ;; Configure hooks to automatically turn-on eglot for selected modes
+ ; :hook
+ ; (((python-mode ruby-mode elixir-mode) . eglot))
+
+ :custom
+ (eglot-send-changes-idle-time 0.1)
+
+ :config
+ (fset #'jsonrpc--log-event #'ignore) ; massive perf boost---don't log every event
+ ;; Sometimes you need to tell Eglot where to find the language server
+ ; (add-to-list 'eglot-server-programs
+ ; '(haskell-mode . ("haskell-language-server-wrapper" "--lsp")))
+ (add-to-list 'eglot-server-programs
+ '(python-ts-mode . ("pylsp" "--tcp" "--port" :autoport)))
+ )
+
+;; YAML
+(use-package yaml-mode :ensure t)
+
+;; JSON
+(use-package json-mode :ensure t)
+(add-hook 'js-json-mode-hook
+ (lambda ()
+ (define-key js-json-mode-map (kbd "<f5>") 'json-pretty-print-buffer)))
+
+;; Lisp
+(use-package slime :defer t :ensure t)
+(setq inferior-lisp-program "sbcl")
+
+;; Rest client
+(use-package restclient :defer t :ensure t)
+
+;; Magit
+(use-package magit
+ :ensure t
+ :bind (("s-g" . magit-status)
+ ("C-c g" . magit-status)))
+
+;; python-mode configuration
+
+(use-package pyvenv
+ :ensure t
+ :config
+ ;; Set correct Python interpreter
+ (setq pyvenv-post-activate-hooks
+ (list (lambda ()
+ (setq python-shell-interpreter (concat pyvenv-virtual-env "bin/python3")))))
+ (setq pyvenv-post-deactivate-hooks
+ (list (lambda ()
+ (setq python-shell-interpreter "python3")))))
+
+(use-package python-pytest
+ :defer t
+ :ensure t
+ :config
+ (transient-append-suffix
+ 'python-pytest-dispatch
+ "-v"
+ '("--db" "Create db" "--create-db")))
+
+(add-hook 'python-ts-mode-hook
+ (lambda ()
+ (define-key python-ts-mode-map (kbd "C-c p") 'python-pytest-dispatch)
+ (define-key python-ts-mode-map (kbd "C-c m p") 'ceg/pre-commit-run-current-file)))
+
+;; Load path from shell environment
+(use-package exec-path-from-shell :ensure t :defer t)
+
+;; sh-mode configuration
+(use-package flymake-shellcheck
+ :commands flymake-shellcheck-load
+ :init
+ (add-hook 'sh-mode-hook 'flymake-shellcheck-load))
+
+
+;; Moodline
+(use-package mood-line :ensure t)
+(mood-line-mode)
+
+;; Fix for flycheck with eglot
+;; https://gitlab.com/jessieh/mood-line/-/merge_requests/11
+(require 'cl-lib)
+
+(defun mood-line--checker-flymake-count-errors ()
+ "Return alist with count of all current flymake diagnostic reports.
+
+Counts will be returned in an alist as the cdr of the following keys:
+`'note-count' | All notes reported by checker
+`'error-count' | All errors reported by checker
+`'warning-count' | All warnings reported by checkero
+`'issue-count' | All errors and warnings reported by checker
+`'all-count' | Everything reported by checker"
+ (let ((error-count 0)
+ (warning-count 0)
+ (note-count 0))
+ (progn
+ (cl-loop
+ with warning-level = (warning-numeric-level :warning)
+ with note-level = (warning-numeric-level :debug)
+ for state being the hash-values of flymake--state
+ do (cl-loop
+ with diags = (flymake--state-diags state)
+ for diag in diags do
+ (let ((severity (flymake--lookup-type-property (flymake--diag-type diag) 'severity
+ (warning-numeric-level :error))))
+ (cond ((> severity warning-level) (cl-incf error-count))
+ ((> severity note-level) (cl-incf warning-count))
+ (t (cl-incf note-count)))))))
+ `((note-count . ,note-count)
+ (error-count . ,error-count)
+ (warning-count . ,warning-count)
+ (issue-count . ,(+ warning-count
+ error-count))
+ (all-count . ,(+ note-count
+ warning-count
+ error-count)))))
+
+;; IMenu everywhere
+(use-package imenu-anywhere
+ :ensure t
+ :bind (("C-." . imenu-anywhere)))
+
+;; Projectile
+(use-package projectile
+ :init
+ (setq projectile-use-git-grep t))
+(projectile-mode +1)
+(define-key projectile-mode-map (kbd "M-p") 'projectile-command-map)
+
+
+(use-package projectile-rails
+ :defer t :ensure t
+ :init (projectile-rails-global-mode))
+(define-key projectile-rails-mode-map (kbd "C-c r")
+ 'projectile-rails-command-map)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;
+;;; Custom functions
+;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defun ceg/pre-commit-run-current-file ()
+ "Run pre-commit with the current file name"
+ (interactive)
+ (let ((full-command (concat "pre-commit run --file " buffer-file-name " | sed 's;^ceg/;;g'")))
+ (compile full-command)))
+
+(defun ceg/pre-commit-run ()
+ "Run pre-commit with the current file name"
+ (interactive)
+ (let ((full-command (concat "pre-commit run | sed 's;^ceg/;;g'")))
+ (compile full-command)))
+
+(add-hook 'python-mode (lambda ()
+ (local-set-key ("C-c o")
+ 'ceg/pre-commit-run)))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;
+;;; Global keybindigns
+;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(define-key global-map (kbd "RET") 'newline-and-indent)
+(global-set-key (kbd "C-x C-b") 'ibuffer)
+(global-set-key (kbd "C-;") 'completion-at-point)
+(global-set-key (kbd "C-x g") 'magit-status)
+(global-set-key (kbd "M-z") 'zap-up-to-char)
+(global-set-key (kbd "C-.") #'imenu-anywhere)
+(global-set-key (kbd "M-o") 'other-window)
+(custom-set-variables
+ ;; custom-set-variables was added by Custom.
+ ;; If you edit it by hand, you could mess it up, so be careful.
+ ;; Your init file should contain only one such instance.
+ ;; If there is more than one, they won't work right.
+ '(custom-safe-themes
+ '("919fabfc5cb6165ce07b9d8668f78fe75fe8bd08566006bc87513c29b4f34ade" "3770d0ae70172461ee0a02edcff71b7d480dc54066e8960d8de9367d12171efb" default))
+ '(safe-local-variable-values
+ '((python-pytest-executable . "pytest")
+ (python-shell-interpreter-args . "/home/work/Workspace/ceg-intranet/ceg/manage.py shell_plus --plain"))))
+(custom-set-faces
+ ;; custom-set-faces was added by Custom.
+ ;; If you edit it by hand, you could mess it up, so be careful.
+ ;; Your init file should contain only one such instance.
+ ;; If there is more than one, they won't work right.
+ )