Skip to content

tocxjo/emacs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MELPA

;;; -*- lexical-binding: t -*-
(require 'package)
(setq package-archives
  '(("MELPA"        . "https://melpa.org/packages/")
    ("GNU ELPA"     . "https://elpa.gnu.org/packages/")))
(package-initialize)

EMACS CONFIG

;; disable backup files
(setq make-backup-files nil)

;; disable basic UI
;; (menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)

;; disable cursor blink
(blink-cursor-mode -1)

;; better visualization
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
(setq-default fill-column 80)

;; relative line numbers
(global-display-line-numbers-mode t)
(setq display-line-numbers-type 'relative)

;; ignore case while searching
(setq case-fold-search t)
(setq grep-command "rg --no-heading --vimgrep --smart-case ")

;; no startup screen and no scratch
(setq inhibit-startup-screen t)

;; enable tab-bar mode
(tab-bar-mode 1)

(set-language-environment "Japanese")

;; set coding system to UTF-8
(set-language-environment "UTF-8")
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(setq buffer-file-coding-system 'utf-8)

;; alias for y/n/p
(defalias 'yes-or-no-p 'y-or-n-p)

;; border
(setq default-frame-alist '((internal-border-width . 12)))
;; start emacs maximized
(add-to-list 'default-frame-alist '(fullscreen . maximized))

;; opacity
(set-frame-parameter (selected-frame) 'alpha '(95 . 95))

;; pomodoro sound
(setq org-clock-sound "clave.wav")

;; tramp stuff
(setq tramp-default-method "ssh")
(setq tramp-verbose 10)
(setq tramp-ssh-controlmaster-options "-o ControlMaster=auto -o ControlPath='~/.ssh/ssh-%%r@%%h:%%p' -o ControlPersist=yes")

;; hide emphasis markers in org mode
(setq org-hide-emphasis-markers t)

;; change diary file location to ~/org
(setq diary-file "~/org/diary")

;; fix magit for windows
(with-eval-after-load 'server
  (when (eq system-type 'windows-nt)
    (defun server-ensure-safe-dir (dir) "Noop" t)))

lsp-java windows configuration

(when (eq system-type 'windows-nt)
  (setenv "JAVA_HOME" "C:/Program Files/Java/jdk-21/")
  (setq lsp-java-java-path "C:/Program Files/Java/jdk-21/bin/java.exe"))

prettify symbols

 (add-hook
  'go-mode-hook
  (lambda ()
    (push '("exists" . ?∃) prettify-symbols-alist)
    (push '(":= range" . ?∈) prettify-symbols-alist)
    (push '("==" . ?≡) prettify-symbols-alist)
    (push '(">=" . ?≥) prettify-symbols-alist)
    (push '("<=" . ?≤) prettify-symbols-alist)
    (push '("<-" . ?←) prettify-symbols-alist)
    (push '("!=" . ?≠) prettify-symbols-alist)
    (push '("&&" . ?∧) prettify-symbols-alist)
    (push '("||" . ?∨) prettify-symbols-alist)
    (push '("!" . ) prettify-symbols-alist)
    ))

 (add-hook
'c-mode-common-hook 
(lambda ()
  (push '("==" . ?≡) prettify-symbols-alist)
  (push '("!=" . ?≠) prettify-symbols-alist)
  (push '(">=" . ?≥) prettify-symbols-alist)
  (push '("<=" . ?≤) prettify-symbols-alist)
  (push '("&&" . ?∧) prettify-symbols-alist)
  (push '("||" . ?∨) prettify-symbols-alist)
  (push '("!" . ) prettify-symbols-alist)
  (push '("->" . ?→) prettify-symbols-alist)
  (push '("*" . ?∗) prettify-symbols-alist) ; Para punteros
  ))

 (add-hook
'java-mode-common-hook 
(lambda ()
  (push '("==" . ?≡) prettify-symbols-alist)
  (push '("!=" . ?≠) prettify-symbols-alist)
  (push '(">=" . ?≥) prettify-symbols-alist)
  (push '("<=" . ?≤) prettify-symbols-alist)
  (push '("&&" . ?∧) prettify-symbols-alist)
  (push '("||" . ?∨) prettify-symbols-alist)
  (push '("!" . ) prettify-symbols-alist)
  (push '("->" . ?→) prettify-symbols-alist)
  (push '("*" . ?∗) prettify-symbols-alist) ; Para punteros
  ))

 (global-prettify-symbols-mode 't)

EVIL MODE

(use-package evil
  :ensure t
  :init
  (setq evil-want-keybinding nil)
  :config
  ;; (evil-define-key 'normal org-mode-map (kbd "TAB") 'org-cycle)
  ;; (evil-define-key 'visual org-mode-map (kbd "TAB") 'org-cycle)
  ;; (evil-define-key 'motion org-mode-map (kbd "TAB") 'org-cycle)
  ;; (with-eval-after-load 'evil-maps
  ;;   (define-key evil-motion-state-map (kbd "SPC") nil)
  ;;   (define-key evil-motion-state-map (kbd "RET") nil)
  ;;   (define-key evil-motion-state-map (kbd "TAB") nil))
  (define-key evil-motion-state-map (kbd "RET") nil)
  (evil-mode 1)
  (evil-set-undo-system 'undo-redo))

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

(use-package evil-org
  :ensure t
  :hook (org-mode . evil-org-mode)
  :config
  (evil-org-set-key-theme '(navigation insert textobjects additional calendar))
  (require 'evil-org-agenda)
  (evil-org-agenda-set-keys))

(use-package evil-smartparens
  :ensure t
  :config
  (add-hook 'smartparens-enabled-hook #'evil-smartparens-mode))

GENERAL KEYBINDINGS

creating functions for keybindings

(defun pomodoro-start ()
  (interactive)
  (org-timer-set-timer 25))

(defun pomodoro-long-break ()
  (interactive)
  (org-timer-set-timer 15))

(defun goto-config ()
  (interactive)
  (find-file (expand-file-name "config.org" user-emacs-directory)))

(defun pomodoro-break ()
  (interactive)
  (org-timer-set-timer 5))

(defun reload-config ()
  (interactive)
  (load-file (expand-file-name "init.el" user-emacs-directory)))

define keybindings

  (use-package general
    :ensure t)

  (general-create-definer my-leader-def
    :prefix "SPC"
    :non-normal-prefix "M-SPC")

  (general-define-key
   :keymaps 'evil-insert-state-map
   "SPC" 'self-insert-command)

  ;; f8 to show treemacs (NOT USED)
  ;; (global-set-key (kbd "<f8>") 'treemacs)

  ;; f8 to show neotree
  (global-set-key (kbd "<f8>") 'neotree-toggle)

  (my-leader-def
   :keymaps 'evil-normal-state-map
   "f"  '(:ignore t :which-key "file")
   "fc" '(compile :which-key "compile file")
   "fd" '(find-file-in-directory :which-key "find file in directory")
   "ff" '(find-file :which-key "find file")
   "fp" '(goto-config :which-key "open config.org")
   "fr" '(recentf :which-key "recent files")
   "fs" '(save-buffer :which-key "save file")

   "."  '(find-file :which-key "find file")

   "b"  '(:ignore t :which-key "buffer")
   "bb" '(switch-to-buffer :which-key "switch to buffer")
   "bd" '(kill-buffer :which-key "delete buffer")
   "bj" '(previous-buffer :which-key "previous buffer")
   "bk" '(next-buffer :which-key "next buffer")
   "bl" '(buffer-menu :which-key "buffer menu")

   "g"  '(:ignore t :which-key "git")
   "gC" '(magit-clone :which-key "clone git repo")
   "gc" '(magit-commit :which-key "commit git message")
   "gd" '(magit-diff :which-key "show git diff")
   "gg" '(magit-status :which-key "open git status")
   "gl" '(magit-log :which-key "open git log")
   "gp" '(magit-push :which-key "push git repo")
   "gr" '(magit-run :which-key "run git command")
   "gs" '(magit-stage :which-key "stage git changes")

   "h"  '(:ignore t :which-key "help")
   "hf" '(describe-function :which-key "describe function")
   "hm" '(man :which-key "manual entries")
   "hr" '(reload-config :which-key "reload init.el")

   "ht" '(consult-theme :which-key "load theme")
   "hv" '(describe-variable :which-key "describe variable")

   "n"  '(:ignore t :which-key "org-roam nodes")
   "nf" '(org-roam-node-find :which-key "find node")
   "ng" '(org-roam-ui-open :which-key "node graph")
   "ni" '(org-roam-node-insert :which-key "insert node")
   "nl" '(org-roam-buffer-toggle :which-key "toggle backlink buffer")
   "nt" '(org-roam-tag-add :which-key "add tag")

   "o"  '(:ignore t :which-key "org-mode commands")
   "oa" '(org-agenda :which-key "open org-agenda")
   "oc" '(org-goto-calendar :which-key "open org-calendar")
   "oe" '(org-export-dispatch :which-key "export to:")
   "oi" '(:ignore t :which-key "insert")
   "oi," '(org-insert-structure-template :which-key "insert structure")
   "oi." '(org-time-stamp :which-key "insert timestamp")
   "oid" '(org-deadline :which-key "insert deadline")
   "oih" '(org-insert-heading :which-key "insert heading")
   "oil" '(org-insert-link :which-key "insert link")
   "oip" '(org-set-property :which-key "insert property")
   "ois" '(org-schedule :which-key "insert schedule")
   "oit" '(org-table-create-or-convert-from-region :which-key "insert table from region")
   "oo" '(org-open-at-point :which-key "open link")
   "os" '(org-sort :which-key "sort current subtree or list")

   "p"   '(:ignore t :which-key "pomodoro")
   "p."  '(org-timer-pause-or-continue :which-key "pause or resume pomodoro")
   "pb"  '(pomodoro-break :which-key "pomodoro break")
   "pl"  '(:ignore t :which-key "long break")
   "plb" '(pomodoro-long-break :which-key "pomodoro long break")
   "pp"  '(pomodoro-start :which-key "start pomodoro")
   "ps"  '(org-timer-stop :which-key "stop pomodoro")

   "r"   '(:ignore t :which-key "bookmarks")
   "rj"  '(bookmark-jump :which-key "jump to bookmark")
   "rs"  '(bookmark-set :which-key "set to bookmark")

   "s"  '(:ignore t :which-key "search")
   "sg" '(rg-project :which-key "ripgrep project")
   "so" '(sort-lines :which-key "sort lines")
   "ss" '(swiper :which-key "swiper")

   "t"  '(:ignore t :which-key "toggle")
"t TAB" '(tab-bar-mode :which-key "toggle tab bar")


   "TAB"  '(:ignore t :which-key "tab")
   "TAB d" '(tab-close :which-key "close tab")
   "TAB j" '(tab-previous :which-key "previous tab")
   "TAB k" '(tab-next :which-key "next tab")
   "TAB l" '(tab-list :which-key "list of tabs")
   "TAB n" '(tab-new :which-key "new tab")
   "TAB y" '(tab-new :which-key "duplicate tab")
 "TAB TAB" '(tab-recent :which-key "recent tab")

   "w"  '(:ignore t :which-key "window")
   "wh" '(windmove-left :which-key "move left")
   "wj" '(windmove-down :which-key "move down")
   "wk" '(windmove-up :which-key "move up")
   "wl" '(windmove-right :which-key "move right")
   "wt" '(tear-off-window :which-key "tear off window")

   "vt" '(vterm :which-key "vterm"))

  (my-leader-def
   :keymaps 'evil-insert-state-map
  )

  (my-leader-def
   :keymaps 'org-mode-map
   (kbd "<C-c> <C-t>") #'org-todo)

THEME

font

(set-frame-font "jetbrains mono 11" nil t)
;; (set-frame-font "ms gothic 13" nil t)

theme

(use-package doom-themes
  :ensure t)
(use-package tao-theme
  :ensure t)
(use-package nano-theme
  :ensure t)
(use-package ef-themes
  :ensure t)

(setq dark-theme 'doom-tomorrow-night)
(setq light-theme 'doom-tomorrow-day)

(defun night-mode ()
  (interactive)
  (disable-theme light-theme)
  (add-hook 'pdf-view-mode 'pdf-view-midnight-minor-mode t)
  (load-theme dark-theme t))

(defun day-mode ()
  (interactive)
  (disable-theme dark-theme)
  (add-hook 'pdf-view-mode 'pdf-view-midnight-minor-mode nil)
  (load-theme light-theme t))

(defun toggle-day-night-mode ()
  (interactive)
  (let* ((current-time (current-time))
         (current-hour (nth 2 (decode-time current-time))))
    (if (or (> current-hour 20) (< current-hour 6))
        (night-mode)
      (day-mode))))

(toggle-day-night-mode)

PACKAGES

pdf

(use-package pdf-tools
  :ensure t
  :pin manual
  :config
  (pdf-tools-install)
  (setq-default pdf-view-display-size 'fit-width))

(use-package pdf-view-restore
  :ensure t
  :after pdf-tools
  :config
  (add-hook 'pdf-view-mode-hook 'pdf-view-restore-mode))

auto-complete

(use-package auto-complete
    :ensure t
    :config
    (ac-config-default))

flycheck (syntax-checking)

(use-package flycheck
     :ensure t)

elcord (rpc)

(use-package elcord
  :ensure t
  :config
  (setq elcord-client-id "1333674662613356554")
  (elcord-mode 1))

gcmh (garbage collector)

(use-package gcmh
  :ensure t)
(gcmh-mode 1)

keepass

(use-package keepass-mode
  :ensure t
  :config)

jabber

(use-package jabber
    :ensure t)

(setq jabber-account-list
    `((,(getenv "JABBER_USER")
       (:password . ,(getenv "JABBER_PASSWORD"))
       (:network-server . ,(getenv "JABBER_SERVER"))
       (:connection-type . ssl))))

(setq jabber-auto-reconnect t)
(setq jabber-history-enabled t)

smartparens

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

indentation

(use-package aggressive-indent
    :ensure t
    :config
    (global-aggressive-indent-mode t))

which-key

(use-package which-key
  :ensure t
  :config
  (setq which-key-side-window-location 'bottom)
  (setq which-key-max-display-columns nil)
  (setq which-key-min-display-lines 1)
  (which-key-mode)
  (setq which-key-idle-delay 0))

popup

(use-package vertico
  :ensure t
  :init
  (vertico-mode))

(use-package consult
  :ensure t
  :config)

(use-package marginalia
  :ensure t
  :init
  (marginalia-mode))

lsp-mode

(use-package lsp-mode
  :ensure t
  :defer t
  :hook ((python-mode . lsp)
         (c++-mode . lsp)
         (java-mode . lsp)
         (js-mode . lsp)
         (html-mode . lsp)
         (css-mode . lsp)
         (go-mode . lsp))
  :commands lsp)

(use-package lsp-ui
  :ensure t
  :after lsp-mode
  :config
  (setq lsp-ui-sideline-enable t
        lsp-ui-doc-enable t
        lsp-ui-imenu-enable t)
  :hook (lsp-mode . lsp-ui-mode))

(use-package company
  :ensure t
  :after lsp-mode
  :config
  (setq company-idle-delay 0.01)
  (add-hook 'lsp-mode-hook 'company-mode))

(use-package dap-mode
  :ensure t
  :after lsp-mode
  :config
  (dap-mode 1)
  (dap-ui-mode 1))

company-mode

(use-package company
  :ensure t
  :config
  (add-hook 'after-init-hook 'global-company-mode))

yasnippet

(use-package yasnippet
  :ensure t
  :config
  (yas-global-mode 1))

(use-package yasnippet-snippets
  :ensure t
  :after yasnippet)

yafolding

(use-package yafolding
  :ensure t)

magit

(use-package magit
  :ensure t)

orderless

(use-package orderless
  :ensure t
  :custom
  (completion-styles '(orderless basic))
  (completion-category-overrides '((file (styles basic partial-completion)))))

nyan-mode

(use-package nyan-mode
  :ensure t
  :config
  (nyan-mode 1)) 

neotree

(use-package neotree
  :ensure t)

(use-package neotree
  :after (neotree)
  :ensure t)

;; disable line numbers in neotree's window
(add-hook 'neo-after-create-hook
        (lambda (&optional dummy)
          (display-line-numbers-mode -1)))

(setq neo-theme 'nerd-icons)

dashboard

(use-package dashboard
  :ensure t
  :config
  (setq dashboard-items '((recents  . 5)
                          (bookmarks . 5)
                          (agenda . 5)
                          (projects . 5)))
  (setq dashboard-set-heading-icons t
        dashboard-set-file-icons t
        dashboard-startup-banner 'official)
  (add-hook 'dashboard-after-initialize-hook 'neotree-toggle)
  (dashboard-setup-startup-hook))

dirvish

(use-package dirvish
  :ensure t)

nerd-icons

(use-package nerd-icons
  :ensure t
  :custom
  (nerd-icons-font-family "JetBrainsMono NF"))

yafolding

(use-package yafolding
    :ensure t
    :config
    :hook (prog-mode . yafolding-mode))

HOOKS

org-mode

(use-package org-fragtog
  :ensure t)
(add-hook 'org-mode-hook 'org-fragtog-mode)
(add-hook 'org-mode-hook 'org-display-inline-images)

pdf-tools

(add-hook 'pdf-view-mode-hook
    (lambda ()
        (display-line-numbers-mode -1)
        (blink-cursor-mode -1)))

ORG MODE

org-roam

(use-package org-roam
  :ensure t
  :init
  (setq org-roam-v2-ack t)
  (setq org-roam-graph-executable "dot")
  :custom
  (org-roam-directory "~/org")
  :config
  (org-roam-setup))

(defun my/org-roam-node-has-tag (node tag)
  (member tag (org-roam-node-tags node)))

(defun my/org-roam-node-find-by-tag ()
  (interactive)
  (let ((tag (read-string "Enter tag: ")))
    (org-roam-node-find nil nil (lambda (node) (my/org-roam-node-has-tag node tag)))))

(setq org-roam-completion-system 'ido)

(setq org-roam-capture-templates
    '(("d" "default" plain "%?"
       :target (file+head "${slug}.org" "#+options: toc:nil\n#+title: ${title}\n#+created: %<%Y-%m-%d>\n")
       :unnarrowed t)))

deft

(use-package deft
  :ensure t)
(setq deft-directory "~/org")

export to ~/org/exports

(setq org-publish-project-alist
'(("html"
   :base-directory "~/org/"
   :base-extension "org"
   :publishing-directory "~/org/exports"
   :publishing-function org-html-export-to-html)
  ("pdf"
   :base-directory "~/org/"
   :base-extension "org"
   :publishing-directory "~/org/exports"
   :publishing-function org-latex-export-to-pdf)
  ("all" :components ("html" "pdf"))))

org-agenda

(setq org-agenda-files '("~/org"))

DIRECTORY SHORTCUTS

(setq directories
'((proj . "~/projects/")
  (docs . "~/Documents/")
  (books . "f:/books/")
  (org . "~/org/")
  (downloads . "~/Downloads/")))

(defun find-file-in-directory (alias)
(interactive
 (list (intern (completing-read "choose directory: " (mapcar (lambda (pair) (symbol-name (car pair))) directories)))))
(let ((dir (cdr (assoc alias directories))))
  (if dir
      (let ((file (read-file-name "select file: " dir)))
        (find-file file))
    (message "directory not found"))))

About

emacs config

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published