Skip to content

Instantly share code, notes, and snippets.

@Programator2
Last active March 4, 2025 19:34
Show Gist options
  • Save Programator2/b8b4cdeb6f54d35226ee5f24ec4d0838 to your computer and use it in GitHub Desktop.
Save Programator2/b8b4cdeb6f54d35226ee5f24ec4d0838 to your computer and use it in GitHub Desktop.
Programator2's Emacs config
;;; init.el --- Personal EMACS config by Programator2 -*- lexical-binding: t; -*-
;; Copyright (C) 2018-2025 Roderik Ploszek
;; Author: Roderik Ploszek <[email protected]>
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Nothing too spectacular, I put it here so I can copy it quickly to other
;; machines. This is my quick and dirty config for new machines. I'm currently
;; using something more elaborate and I may someday finally put it on GitHub
;; once I get to clean it up a bit.
;;; Code:
;; garbage collection activates above 384 MB or when 60 % of the heap has been
;; allocated (thanks spacemacs project)
(setq gc-cons-threshold 402653184 gc-cons-percentage 0.6)
;; Need to load
(if (version< emacs-version "27")
(package-initialize))
;; MELPA
(require 'package)
(add-to-list 'package-archives (cons "melpa" "https://melpa.org/packages/") t)
(add-to-list 'package-archives '("nongnu" . "https://elpa.nongnu.org/nongnu/"))
;;; Setup use-package
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(eval-when-compile
(require 'use-package))
(setq use-package-always-ensure t)
(setq use-package-always-defer t)
(setq use-package-compute-statistics t)
;; this allows introspection of hooks, you have to use the full name
(setq use-package-hook-name-suffix nil)
;; ENTER jumps to a link
(setq org-return-follows-link t)
;; org-babel
(org-babel-do-load-languages
'org-babel-load-languages
'((perl . t)))
;; bodka za vetou konci jednou medzerou
(setq-default sentence-end-double-space nil)
;; recentf-mode
(recentf-mode 1)
(setq recentf-max-saved-items 1000)
;; show parantheses
(show-paren-mode 1)
;; view line number in mode line
(line-number-mode 1)
(blink-cursor-mode 0)
;; set if you want to highlight current line
(global-hl-line-mode 1)
;; Show a context menu on right click (Emacs 28 required) (modern-feature)
(if (version<= "28" emacs-version)
(context-menu-mode 1))
;; line numbers in programming modes
;; WARNING: don't use linum-mode! It slows down scrolling!
(add-hook 'prog-mode-hook 'display-line-numbers-mode)
;; hs-minor-mode for code folding (modern-feature)
(add-hook 'prog-mode-hook 'hs-minor-mode)
;; auto-revert in programming modes
(add-hook 'prog-mode-hook 'auto-revert-mode)
;; modernization of editor
(scroll-bar-mode -1)
;; return mark to the previous position if scrolled to the end
(setq scroll-error-top-bottom t)
;; Useless whitespace
;; Automaticky oznac prazdne znaky na konci riadku
(setq-default show-trailing-whitespace t)
;; But not in the calendar
(add-hook 'calendar-mode-hook
(function (lambda () (setq show-trailing-whitespace nil))))
;; Oznac prazdne riadky na konci suboru
(setq-default indicate-empty-lines t)
;; Display time in the modeline, in 24-hour format
(setq display-time-24hr-format t)
(display-time-mode)
;; helm
(use-package helm
:diminish helm-mode
:config (progn
(setq helm-completion-style 'emacs)
(helm-mode))
:bind (
("M-x" . helm-M-x)
("C-x b" . switch-to-buffer)
("C-x b" . helm-buffers-list)
("C-x C-b" . helm-mini)
("C-x C-f" . helm-find-files)
("C-x C-r" . helm-recentf)
))
;; which-key-mode
(use-package which-key
:diminish which-key-mode
:config
(which-key-mode))
;; move between windows using S-<arrow_key>
(windmove-default-keybindings)
;; restore window configuration using C-c left and C-c right
(winner-mode t)
;; Vim-like bindings
;; ffap (gf in Vim, so M-g M-f in Emacs)
(global-set-key (kbd "M-g M-f") 'ffap)
;; M-z is normally zap-to-char, which is less useful than zap-up-to-char
(global-set-key "\M-z" 'zap-up-to-char)
;; 2024-05 Something happened in Windows 11 (AMD graphics driver perhaps) and
;; \M-z doesn't work anymore
(global-set-key (kbd "C-c z") 'zap-up-to-char)
;; When I press M-; I want to comment the current line, not to add a comment at
;; the end of the line. That functionality (comment-dwim) was moved to C-x C-;.
(global-set-key (kbd "M-;") 'comment-line)
(global-set-key (kbd "C-x C-;") 'comment-dwim)
;; set auto fill mode for org-mode
(setq-default fill-column 80)
(add-hook 'org-mode-hook 'turn-on-auto-fill)
;; dni v tyzdni do kalendara
(copy-face font-lock-constant-face 'calendar-iso-week-face)
(set-face-attribute 'calendar-iso-week-face nil
:height 0.8)
(setq calendar-intermonth-text
'(propertize
(format "%2d"
(car
(calendar-iso-from-absolute
(calendar-absolute-from-gregorian (list month day year)))))
'font-lock-face 'calendar-iso-week-face))
;; Monday is the first day of the week
(setq calendar-week-start-day 1)
;; zalohy ukladaj do jednotneho priecinka
(setq backup-directory-alist
'(("." . "~/.emacs.d/backups")))
;; Aby sa subory otvarali tam, kde som ich zanechal
(save-place-mode 1)
;; template system yasnippet
(use-package yasnippet-snippets)
(use-package yasnippet
:defer t
:commands (yas-global-mode yas-minor-mode yas-activate-extra-mode)
:hook (prog-mode-hook . yas-minor-mode)
(org-mode-hook . yas-minor-mode)
:config (yas-global-mode))
;; inspired by https://github.com/xiaoxinghu/dotfiles/blob/master/emacs/.emacs.d/modules/treesitter.el
(use-package treesit
:ensure nil ;; internal package
:commands (treesit-install-language-grammar)
:init
(setq treesit-language-source-alist
'((astro . ("https://github.com/virchau13/tree-sitter-astro"))
(bash . ("https://github.com/tree-sitter/tree-sitter-bash"))
(c . ("https://github.com/tree-sitter/tree-sitter-c"))
(cpp . ("https://github.com/tree-sitter/tree-sitter-cpp"))
(css . ("https://github.com/tree-sitter/tree-sitter-css"))
(go . ("https://github.com/tree-sitter/tree-sitter-go"))
(html . ("https://github.com/tree-sitter/tree-sitter-html"))
(javascript . ("https://github.com/tree-sitter/tree-sitter-javascript"))
(json . ("https://github.com/tree-sitter/tree-sitter-json"))
(lua . ("https://github.com/Azganoth/tree-sitter-lua"))
(make . ("https://github.com/alemuller/tree-sitter-make"))
;; (ocaml . ("https://github.com/tree-sitter/tree-sitter-ocaml" "ocaml/src" "ocaml"))
(python . ("https://github.com/tree-sitter/tree-sitter-python"))
;; (php . ("https://github.com/tree-sitter/tree-sitter-php"))
(typescript . ("https://github.com/tree-sitter/tree-sitter-typescript" "typescript/src" "typescript"))
(tsx . ("https://github.com/tree-sitter/tree-sitter-typescript" "master" "tsx/src"))
(ruby . ("https://github.com/tree-sitter/tree-sitter-ruby"))
(rust . ("https://github.com/tree-sitter/tree-sitter-rust"))
(sql . ("https://github.com/m-novikov/tree-sitter-sql"))
(toml . ("https://github.com/tree-sitter/tree-sitter-toml"))
;; (zig . ("https://github.com/GrayJack/tree-sitter-zig"))
(yaml . ("https://github.com/ikatyang/tree-sitter-yaml"))
))
:config
(treesit-major-mode-setup)
;; (use-package combobulate
;; :preface
;; ;; You can customize Combobulate's key prefix here.
;; ;; Note that you may have to restart Emacs for this to take effect!
;; (setq combobulate-key-prefix "C-c m"))
)
(use-package python
:mode (("SConstruct\\'" . python-ts-mode) ("SConscript\\'" . python-ts-mode))
:hook (python-ts-mode-hook . (lambda ()
;; (require 'lsp-pylsp)
(lsp)
)))
(use-package rg)
(use-package lsp-mode
:diminish lsp-mode
;; uncomment to enable gopls http debug server
;; :custom (lsp-gopls-server-args '("-debug" "127.0.0.1:0"))
:custom
(lsp-keymap-prefix "C-c i")
:commands (lsp lsp-deferred)
:hook
(lsp-mode-hook . lsp-enable-which-key-integration) ;enable which-key integration
:config (progn
;; use flycheck, not flymake
(setq lsp-prefer-flymake nil)
;; lsp needs to read large amounts of data
(setq read-process-output-max (* 1024 1024))))
;; optional - provides fancy overlay information
(use-package lsp-ui
:after lsp-mode
:commands lsp-ui-mode
:config (progn
;; disable inline documentation
;; (setq lsp-ui-sideline-enable nil)
;; disable showing docs on hover at the top of the window
;; (setq lsp-ui-doc-enable nil)
)
)
;;; golang
(use-package go-mode
:bind (
;; If you want to switch existing go-mode bindings to use lsp-mode/gopls instead
;; uncomment the following lines
("C-c C-j" . lsp-find-definition)
("C-c C-d" . lsp-describe-thing-at-point))
:hook ((go-mode-hook . lsp-deferred))
:init (add-hook 'go-mode-hook
(lambda ()
(add-hook 'before-save-hook 'lsp-format-buffer 0 t)
(add-hook 'before-save-hook 'lsp-organize-imports 0 t))))
;; modus-themes provide much better readability and support of modes than any
;; other theme currently available. Thank you Prot!
;;
(use-package modus-themes
:config
(setq modus-themes-bold-constructs t
modus-themes-completions '((matches) (selection))
modus-themes-headings '((1 rainbow))
modus-themes-italic-constructs t
modus-themes-mixed-fonts t
modus-themes-variable-pitch-ui t)
(setq modus-themes-common-palette-overrides
`(
;; From the section "Make the mode line borderless"
(border-mode-line-active unspecified)
(border-mode-line-inactive unspecified)
;; Make the fringe invisible
(fringe unspecified)
;; Remove underlines from links
(underline-link unspecified)
(underline-link-visited unspecified)
(underline-link-symbolic unspecified)
(bg-link bg-blue-nuanced)
(bg-tab-bar bg-main)
(bg-tab-current bg-cyan-intense)
(bg-tab-other bg-inactive)
)
modus-operandi-tinted-palette-overrides
`(
(bg-mode-line-active "#cab9b2")
))
(defun rod-modus-themes-custom-faces ()
(modus-themes-with-colors
(custom-set-faces
;; Make tooltips readable --RP
`(tooltip ((,c :background ,bg-blue-subtle :foreground ,fg-main)))
;; Add "padding" to the mode lines
`(mode-line ((,c :box (:line-width 3 :color ,bg-mode-line-active))))
`(mode-line-inactive ((,c :box (:line-width 3 :color ,bg-mode-line-inactive))))
;;;; helm
`(helm-selection ((,c :inherit bold :background ,bg-hl-line :extend t :distant-foreground ,magenta-cooler)))
`(helm-match ((,c :inherit bold :foreground ,magenta-cooler :distant-foreground ,fg-main)))
`(helm-source-header ((,c :background ,bg-inactive :foreground ,keyword :weight bold)))
`(helm-visible-mark ((,c :inherit (bold highlight))))
`(helm-moccur-buffer ((,c :inherit link)))
`(helm-ff-file ((,c :foreground ,fg-main)))
`(helm-ff-prefix ((,c :foreground ,keyword)))
`(helm-ff-dotted-directory ((,c :foreground ,fg-alt)))
`(helm-ff-directory ((,c :foreground ,variable)))
`(helm-ff-executable ((,c :foreground ,fg-main :inherit italic)))
`(helm-grep-match ((,c :foreground ,magenta-cooler :distant-foreground ,red-cooler)))
`(helm-grep-file ((,c :foreground ,fnname)))
`(helm-grep-lineno ((,c :foreground ,fg-alt)))
`(helm-grep-finish ((,c :foreground ,cyan-cooler)))
`(helm-locate-finish ((,c :foreground ,green)))
`(helm-separator ((,c :foreground ,red-warmer)))
`(helm-candidate-number ((,c :background ,bg-blue-intense :foreground ,fg-main)))
`(helm-lisp-show-completion ((,c :background ,bg-sage)))
`(org-agenda-date-today ((,c :inherit org-agenda-date :background ,bg-blue-nuanced :underline nil)))
`(holiday ((,c :background ,bg-magenta-nuanced :foreground ,date-holiday)))
)))
;; Hook doesn't work. Don't know why. Calling it explicitly after loading the
;; theme four lines below.
;;
(add-hook 'modus-themes-after-load-theme-hook #'rod-modus-themes-custom-faces)
(load-theme 'modus-vivendi :no-confim)
(rod-modus-themes-custom-faces)
)
;; change garbage collection to a more suitable value (~50MB, spacemacs uses
;; ~100MB)
(setq gc-cons-threshold 50000000 gc-cons-percentage 0.1)
;; use M-x eval-buffer to reload this file
(provide 'init)
;;; init.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment