Configure built-in packages before everything else

This commit is contained in:
Gergely Polonkai 2023-10-15 07:14:37 +02:00
parent cde06cd98d
commit e17223828e
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4

View File

@ -897,15 +897,376 @@ These are disabled for a reason, but im a rockstar, so who cares‽
(put 'list-timers 'disabled nil)
#+end_src
* Emacs configuration
* Global built-in packages
** ~simple.el~ settings
** ~simple~, to always show the current column, and using visual lines in text modes
Column numbers help a lot in debugging, while visual line mode is easier on the eye when writing long text.
#+begin_src emacs-lisp
(use-package simple
:ensure nil
:custom
(column-number-mode t))
(column-number-mode t)
:hook
(text-mode . (lambda () (visual-line-mode t))))
#+end_src
** ~prog-mode~
Plus prettify all the symbols!
#+begin_src emacs-lisp
(use-package prog-mode
:ensure nil
:init
(setq prettify-symbols-alist
'(("lambda" . ?λ)
("function" . ?ƒ)
("map" . ?↦)
("not" . ?¬)
("and" . ?∧)
("or" . ?)))
:config
(global-prettify-symbols-mode t))
#+end_src
** ~thingatpt~
#+begin_src emacs-lisp
(use-package thingatpt
:ensure nil)
#+end_src
** ~nxml~
#+begin_src emacs-lisp
(use-package nxml-mode
:ensure nil
:custom
(nxml-attribute-indent 4)
(nxml-child-indent 4)
(nxml-outline-child-indent 4))
#+end_src
** ~recentf~
#+begin_src emacs-lisp
(use-package recentf
:ensure nil
:config
(run-at-time nil (* 5 60) 'recentf-save-list)
(add-to-list 'recentf-exclude (expand-file-name "elpa" user-emacs-directory)))
#+end_src
** ~files~
#+begin_src emacs-lisp
(use-package files
:ensure nil
:custom
(make-backup-file-name-function 'xah/backup-file-name))
#+end_src
** ~whitespace~
~whitespace-mode~ is turned on by default, and can be toggled with ~F10~.
#+begin_src emacs-lisp
(defun prevent-whitespace-mode-for-some ()
"Prevent whitespace-mode from running in some modes."
(and
(not (derived-mode-p 'magit-mode))
(not (derived-mode-p 'org-mode))))
(use-package whitespace
:demand
:config
(add-function :before-while whitespace-enable-predicate 'prevent-whitespace-mode-for-some)
(global-whitespace-mode 1)
:custom
(whitespace-line-column 100)
:bind
(([f10] . whitespace-mode)
([(shift f10)] . global-whitespace-mode)
:map gpolonkai/pers-map
("w" . whitespace-cleanup))
:custom-face
(whitespace-line ((t (:inherit nil :background "orange4")))))
#+end_src
** ~eshell~
This is a function to delete a character, or close ~eshell~ if theres nothing to delete. Taken
from [[https://ryuslash.org/posts/C-d-to-close-eshell.html][here]].
#+begin_src emacs-lisp
(defun eshell-C-d ()
"Either call `delete-char' interactively or quit."
(interactive)
(condition-case err
(call-interactively #'delete-char)
(error (if (and (eq (car err) 'end-of-buffer)
(looking-back eshell-prompt-regexp nil))
(kill-buffer)
(signal (car err) (cdr err))))))
#+end_src
Function to bind it locally to =C-d=.
#+begin_src emacs-lisp
(defun gpolonkai/eshell-set-c-d-locally ()
(local-set-key (kbd "C-d") #'eshell-C-d))
#+end_src
Now set up eshell.
#+begin_src emacs-lisp
(use-package eshell
:bind
(:map gpolonkai/pers-map
("e" . eshell))
:hook
(eshell-mode . gpolonkai/eshell-set-c-d-locally))
#+end_src
** ~calendar~ & Co.
#+begin_src emacs-lisp
(use-package calendar
:ensure nil
:custom
(calendar-week-start-day 1))
(use-package cal-dst
:ensure nil
:custom
(calendar-time-zone 60)
(calendar-standard-time-zone-name "CET")
(calendar-daylight-time-zone-name "CEST"))
(use-package solar
:ensure nil
:custom
(calendar-latitude 47.4)
(calendar-longitude 19.0)
(calendar-location-name "Budapest, Hungary"))
#+end_src
*** Add Hungarian holidays to the calendar
I know this is the builtin packages section. Sorry for cheating.
#+begin_src emacs-lisp
(use-package hungarian-holidays
:config
(hungarian-holidays-add))
#+end_src
*** Add some other important dates to the calendar
#+begin_src emacs-lisp
(add-to-list 'holiday-other-holidays '(holiday-float 7 5 -1 "SysAdmin Day") t)
(add-to-list 'holiday-other-holidays '(holiday-fixed 10 21 "Reptile Awareness Day") t)
#+end_src
** ~saveplace~
#+begin_src emacs-lisp
(use-package saveplace
:ensure nil
:config
(save-place-mode 1)
:custom
(save-place-file (expand-file-name ".places" user-emacs-directory)))
#+end_src
** ~ediff~
#+begin_src emacs-lisp
(use-package ediff
:ensure nil
:custom
(ediff-merge-split-window-function 'split-window-horizontally)
(ediff-split-window-function 'split-window-vertically)
(ediff-window-setup-function 'ediff-setup-windows-plain))
#+end_src
** ~autorevert~
…unless they are modified, of course.
#+begin_src emacs-lisp
(use-package autorevert
:ensure nil
:config
(global-auto-revert-mode 1))
#+end_src
** ~eww~
For in-Emacs browsing needs.
#+begin_src emacs-lisp
(use-package eww
:custom
(eww-search-prefix "https://duckduckgo.com/html/?q="))
#+end_src
** ~electric~, for automatic indentation
#+begin_src emacs-lisp
(use-package electric
:config
;; This seems to be the default, but lets make sure…
(electric-indent-mode 1))
#+end_src
** ~savehist~
#+begin_src emacs-lisp
(use-package savehist
:config
(savehist-mode 1))
#+end_src
** ~webjump~
#+begin_src emacs-lisp
(use-package webjump
:bind
(:map gpolonkai/pers-map
("j" . webjump)))
#+end_src
** ~which-func~
#+begin_src emacs-lisp
(defun gpolonkai/activate-which-func-mode ()
(if (fboundp 'which-function-mode)
(which-function-mode)
(which-func-mode)))
#+end_src
Enable ~which-func-mode~ in every ~prog-mode~ derived mode.
#+begin_src emacs-lisp
(use-package which-func
:config
(setq which-func-unknown "∅")
:hook
(prog-mode . gpolonkai/activate-which-func-mode))
#+end_src
** ~cookie1~, AKA fortune cookies
“Fortunes” are from the Hungarian version an ancient MS-DOS based program called ~TAGLINE~.
#+begin_src emacs-lisp
(use-package cookie1
:demand t
:custom
(cookie-file (expand-file-name "fortune-cookies.txt" user-emacs-directory))
:bind
(:map gpolonkai/pers-map
("k" . cookie)))
#+end_src
** ~dired~
#+begin_src emacs-lisp
(use-package dired
:ensure nil
:custom
(dired-dwim-target t)
(wdired-create-parent-directories t)
(wdired-allow-to-change-permissions t)
:bind
(:map dired-mode-map
("RET" . dired-find-alternate-file)
("^" . (lambda () (interactive) (find-alternate-file "..")))
("W" . wdired-change-to-wdired-mode)))
#+end_src
** ~goto-addr~, actionable URLs
#+begin_src emacs-lisp
(use-package goto-addr
:hook ((compilation-mode . goto-address-mode)
(prog-mode . goto-address-prog-mode)
(eshell-mode . goto-address-mode)
(shell-mode . goto-address-mode))
:bind
(:map goto-address-highlight-keymap
("<RET>" . goto-address-at-point)
("M-<RET>" . newline))
:commands (goto-address-prog-mode goto-address-mode))
#+end_src
** Do things at ~midnight~
Since my machine (and thus, my Emacs) is turned on pretty much 24/7, its a pretty good idea.
By default, it closes a bunch of unused buffers. I might add some more things there later.
#+begin_src emacs-lisp
(use-package midnight
:ensure nil
:config
(setq clean-buffer-list-kill-never-buffer-names '("*scratch*"
"*Messages*"
"*dashboard*"))
(midnight-mode t))
#+end_src
** ~display-line-numbers~
I usually dont want to see them, but there are occasions when theyre useful.
#+begin_src emacs-lisp
(use-package display-line-numbers
:bind
(:map gpolonkai/pers-map
("C-n" . display-line-numbers-mode)))
#+end_src
** ~ispell~
#+begin_src emacs-lisp
(use-package ispell
:custom
(ispell-dictionary "en_GB")
(ispell-program-name "/usr/bin/hunspell")
:hook
(mail-send . ispell-message)
(message-send . ispell-message))
#+end_src
** ~speedbar~
This is basically just a dependency for [[*projectile-speedbar][projectile-speedbar]].
#+begin_src emacs-lisp
(use-package speedbar)
#+end_src
** ~browse-url~
This is a Termux-specific override.
#+begin_src emacs-lisp
(when (gpolonkai/termux-p)
(use-package browse-url
:ensure nil
:config
(advice-add 'browse-url-default-browser :override
(lambda (url &rest args)
(start-process-shell-command
"open-url"
nil
(concat "am start -a android.intent.action.VIEW --user 0 -d "
url))))))
#+end_src
* Custom commands and functions
@ -1031,356 +1392,6 @@ Lets see if i can get my brain more organised this way…
(org-roam-ui-open-on-start nil))
#+end_src
* Set up global minor modes provided by Emacs
** Pretty lambdas
Because we can.
#+begin_src emacs-lisp
(global-prettify-symbols-mode t)
#+end_src
And set up all the pretty symbols.
#+BEGIN_SRC emacs-lisp
(setq prettify-symbols-alist
'(("lambda" . ?λ)
("function" . ?ƒ)
("map" . ?↦)
("not" . ?¬)
("and" . ?∧)
("or" . ?)))
#+END_SRC
** Treat soft line breaks as hard ones in textual modes
#+BEGIN_SRC emacs-lisp
(add-hook 'text-mode-hook (lambda () (visual-line-mode t)))
#+END_SRC
* Load some built-in libraries
** ~thingatpt~
#+BEGIN_SRC emacs-lisp
(use-package thingatpt
:ensure nil)
#+END_SRC
** Calendar
#+BEGIN_SRC emacs-lisp
(use-package calendar
:ensure nil
:custom
(calendar-week-start-day 1))
(use-package cal-dst
:ensure nil
:custom
(calendar-time-zone 60)
(calendar-standard-time-zone-name "CET")
(calendar-daylight-time-zone-name "CEST"))
(use-package solar
:ensure nil
:custom
(calendar-latitude 47.4)
(calendar-longitude 19.0)
(calendar-location-name "Budapest, Hungary"))
#+END_SRC
*** Add the SysAdmin day to the calendar
Because Im a sysadmin, too.
#+BEGIN_SRC emacs-lisp
(add-to-list 'holiday-other-holidays '(holiday-float 7 5 -1 "SysAdmin Day") t)
(add-to-list 'holiday-other-holidays '(holiday-fixed 10 21 "Reptile Awareness Day") t)
#+END_SRC
** nXML
#+BEGIN_SRC emacs-lisp
(use-package nxml-mode
:ensure nil
:custom
(nxml-attribute-indent 4)
(nxml-child-indent 4)
(nxml-outline-child-indent 4))
#+END_SRC
** ~recentf~
#+BEGIN_SRC emacs-lisp
(use-package recentf
:ensure nil
:config
(run-at-time nil (* 5 60) 'recentf-save-list)
(add-to-list 'recentf-exclude (expand-file-name "elpa" user-emacs-directory)))
#+END_SRC
** ~files~
#+BEGIN_SRC emacs-lisp
(use-package files
:ensure nil
:custom
(make-backup-file-name-function 'xah/backup-file-name))
#+END_SRC
** ~whitespace~
~whitespace-mode~ is turned on by default, and can be toggled with ~F10~.
#+BEGIN_SRC emacs-lisp
(defun prevent-whitespace-mode-for-some ()
"Prevent whitespace-mode from running in some modes."
(and
(not (derived-mode-p 'magit-mode))
(not (derived-mode-p 'org-mode))))
(use-package whitespace
:demand
:config
(add-function :before-while whitespace-enable-predicate 'prevent-whitespace-mode-for-some)
(global-whitespace-mode 1)
:custom
(whitespace-line-column 100)
:bind
(([f10] . whitespace-mode)
([(shift f10)] . global-whitespace-mode)
:map gpolonkai/pers-map
("w" . whitespace-cleanup))
:custom-face
(whitespace-line ((t (:inherit nil :background "orange4")))))
#+END_SRC
** ~eshell~
This is a function to delete a character, or close ~eshell~ if theres nothing to delete. Taken
from [[https://ryuslash.org/posts/C-d-to-close-eshell.html][here]].
#+BEGIN_SRC emacs-lisp
(defun eshell-C-d ()
"Either call `delete-char' interactively or quit."
(interactive)
(condition-case err
(call-interactively #'delete-char)
(error (if (and (eq (car err) 'end-of-buffer)
(looking-back eshell-prompt-regexp nil))
(kill-buffer)
(signal (car err) (cdr err))))))
#+END_SRC
Function to bind it locally to =C-d=.
#+BEGIN_SRC emacs-lisp
(defun gpolonkai/eshell-set-c-d-locally ()
(local-set-key (kbd "C-d") #'eshell-C-d))
#+END_SRC
Now set up eshell.
#+BEGIN_SRC emacs-lisp
(use-package eshell
:bind
(:map gpolonkai/pers-map
("e" . eshell))
:hook
(eshell-mode . gpolonkai/eshell-set-c-d-locally))
#+END_SRC
** ~saveplace~
#+BEGIN_SRC emacs-lisp
;; Save place
(use-package saveplace
:config
(save-place-mode 1)
:custom
(save-place-file (expand-file-name ".places" user-emacs-directory)))
#+END_SRC
** EDiff
#+BEGIN_SRC emacs-lisp
(use-package ediff
:custom
(ediff-merge-split-window-function 'split-window-horizontally)
(ediff-split-window-function 'split-window-vertically)
(ediff-window-setup-function 'ediff-setup-windows-plain))
#+END_SRC
** Automatically revert changed files
…unless they are modified, of course.
#+BEGIN_SRC emacs-lisp
(use-package autorevert
:config
(global-auto-revert-mode 1))
#+END_SRC
** Eww
For in-Emacs browsing needs.
#+BEGIN_SRC emacs-lisp
(use-package eww
:custom
(eww-search-prefix "https://duckduckgo.com/html/?q="))
#+END_SRC
** Electric indent mode
#+BEGIN_SRC emacs-lisp
(use-package electric
:config
;; This seems to be the default, but lets make sure…
(electric-indent-mode 1))
#+END_SRC
** Save history
#+BEGIN_SRC emacs-lisp
(use-package savehist
:config
(savehist-mode 1))
#+END_SRC
** Web jump
#+BEGIN_SRC emacs-lisp
(use-package webjump
:bind
(:map gpolonkai/pers-map
("j" . webjump)))
#+END_SRC
** Which function am i in?
#+BEGIN_SRC emacs-lisp
(defun gpolonkai/activate-which-func-mode ()
(if (fboundp 'which-function-mode)
(which-function-mode)
(which-func-mode)))
#+END_SRC
#+BEGIN_SRC emacs-lisp
(use-package which-func
:config
(setq which-func-unknown "∅")
:hook
(prog-mode . gpolonkai/activate-which-func-mode))
#+END_SRC
** Fortune cookies
The cookies are from the Hungarian version an ancient MS-DOS based program called ~TAGLINE~.
#+BEGIN_SRC emacs-lisp
(use-package cookie1
:demand t
:custom
(cookie-file (expand-file-name "fortune-cookies.txt" user-emacs-directory))
:bind
(:map gpolonkai/pers-map
("k" . cookie)))
#+END_SRC
** Browse URL functionality in Termux
#+BEGIN_SRC emacs-lisp
(when (gpolonkai/termux-p)
(use-package browse-url
:ensure nil
:config
(advice-add 'browse-url-default-browser :override
(lambda (url &rest args)
(start-process-shell-command
"open-url"
nil
(concat "am start -a android.intent.action.VIEW --user 0 -d "
url))))))
#+END_SRC
** Dired customisation
#+BEGIN_SRC emacs-lisp
(use-package dired
:ensure nil
:custom
(dired-dwim-target t)
(wdired-create-parent-directories t)
(wdired-allow-to-change-permissions t)
:bind
(:map dired-mode-map
("RET" . dired-find-alternate-file)
("^" . (lambda () (interactive) (find-alternate-file "..")))
("W" . wdired-change-to-wdired-mode)))
#+END_SRC
** Actionable URLs
#+BEGIN_SRC emacs-lisp
(use-package goto-addr
:hook ((compilation-mode . goto-address-mode)
(prog-mode . goto-address-prog-mode)
(eshell-mode . goto-address-mode)
(shell-mode . goto-address-mode))
:bind
(:map goto-address-highlight-keymap
("<RET>" . goto-address-at-point)
("M-<RET>" . newline))
:commands (goto-address-prog-mode goto-address-mode))
#+END_SRC
** Do things at midnight
By default, it closes a bunch of unused buffers. I might add some more things there later.
#+BEGIN_SRC emacs-lisp
(use-package midnight
:ensure nil
:config
(setq clean-buffer-list-kill-never-buffer-names '("*scratch*"
"*Messages*"
"*dashboard*"))
(midnight-mode t))
#+END_SRC
** Show line numbers
I dont usually like to see them, but there are occasions when they can be useful.
#+BEGIN_SRC emacs-lisp
(use-package display-line-numbers
:bind
(:map gpolonkai/pers-map
("C-n" . display-line-numbers-mode)))
#+END_SRC
** Check for spelling errors
#+BEGIN_SRC emacs-lisp
(use-package ispell
:custom
(ispell-dictionary "en_GB")
(ispell-program-name "/usr/bin/hunspell")
:hook
(mail-send . ispell-message)
(message-send . ispell-message))
#+END_SRC
** Speed bar
#+BEGIN_SRC emacs-lisp
(use-package speedbar)
#+END_SRC
* ~use-package~ packages
** Make sure we have the latest ELPA GPG keys
@ -1777,14 +1788,6 @@ Toggle other windows for maximum focus. When focus is no longer needed, they ca
(bookmarks . 5))))
#+END_SRC
** Hungarian holidays in the Calendar
#+BEGIN_SRC emacs-lisp
(use-package hungarian-holidays
:config
(hungarian-holidays-add))
#+END_SRC
** FlySpell
For all your spell-checking needs.