WIP prestavljanje emacs konfiguracije v literate orgfajl

deblo
Jurij Podgoršek 2023-12-22 02:18:54 +01:00
parent a92b3c8851
commit 02d82c10a4
3 changed files with 224 additions and 131 deletions

196
.emacs.d/config.org 100644
View File

@ -0,0 +1,196 @@
#+TITLE: EMACS konfiguracija
* Splošno
Tukaj se nahaja celotna konfiguracija za emacs urejevalnik, ki jo uporabljam, v ORGMODE obliki. Na ta - "literate programming" oz. pismeni način - podana konfiguracija daje v ospredje opis posameznih sekcij in s tem poveča preglednost, olajša pa tudi navigacijo po konfiguraciji.
Razdeljena je na poglavja ohlapno glede na vlogo oz področje. Področja so nekoliko raznosvrstna (evil način - tipkovnične bližnjice v slogu VIM so ena sekcija, programiranje druga...), bi pa moralo biti iz naslovov precej jasno, za kaj gre.
* Sekcije
** Zagon
~debug-on-error~ uresničimo, če bi radi sprožili razhroščevalnik, kadar pride do napake (zelo priročno pri reševanju težav).
#+begin_src emacs-lisp
(setq debug-on-error t)
#+end_src
Pospešimo zagon z zmanjšanjem frekvence zbiranja smeti (garbage collection).
#+begin_src emacs-lisp
(setq gc-cons-threshold (* 50 1024 1024))
#+end_src
** Paketi
Vklopi prikazovanje statistik naloženih paketov (prikažemo jih z ~M-x use-package-report~).
#+begin_src emacs-lisp
(setq use-package-compute-statistics t)
#+end_src
Nastavimo vire nalaganja paketov in pa vklopimo privzeto nalaganje ~use-package~ paketov iz spletnih zbirališč.
#+begin_src emacs-lisp
(require 'package)
(setq use-package-always-ensure t)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
(add-to-list 'package-archives '("elpa" . "https://elpa.gnu.org/packages/") t)
(package-initialize)
#+end_src
Vklop merjenja časa nalaganja posameznih paketov.
Rezultate merjenja lahko pogledamo z ~M-x benchmark-init/show-durations-tabulated~ ali ~M-x benchmark-init/show-durations-tree~
#+begin_src emacs-lisp
(use-package benchmark-init
:config
;; To disable collection of benchmark data after init is done.
(add-hook 'after-init-hook 'benchmark-init/deactivate))
#+end_src
** EVIL
Ta sekcija vsebuje razne konfiguracije povezane z ~evil-mode~ - modalnim načino editiranja, podobnim vi/vim urejevalnikom.
Vklopi evil mode!
#+begin_src emacs-lisp
(setq evil-want-integration t
evil-want-keybinding nil)
;org-return-follows-link t
(require 'evil)
(evil-mode 1)
#+end_src
Paket ~evil-collection~ pa vsebuje še dodatne evil bližnjice (recimo za ~help-mode~, ~eshell~ in tako dalje).
#+begin_src emacs-lisp
(use-package evil-collection
:after evil
:config
(evil-collection-init))
#+end_src
** Vezane tipke
S paketom ~general~ je definiranih več kategorij tipkovničnih bližnjic, ki so združene po svoji funkciji, podobno kot poglavja tega dokumenta. Če v ukaznem načinu kliknemo ~SPC~ (ali pa v tekstovnem načinu ~C-SPC~), se nam prikažejo tipke kategorij, po kliku na posamezno pa ukazi, ki jih sprožimo (ali pa podkategorije).
V sledečim podpoglavjih so navedene kategorije posameznih bližnjic.
#+begin_src emacs-lisp
(setq kategorije-bliznjic '())
(use-package general
:defer t
:config
(general-evil-setup)
;; Leader key nastavitev (za prozenje ukazov)
(general-create-definer start/leader-keys
:states '(normal insert visual emacs)
:keymaps 'override
:prefix "SPC"
:global-prefix "C-SPC")
#+end_src
*** Splošne bližnice
Tukaj se nahajate samo bližnjici za preklop med bufferji (kako bi to lepo prevedli?).
#+begin_src emacs-lisp
(start/leader-keys
;; Osnovne bliznjice
"[" 'previous-buffer
"]" 'next-buffer)
#+end_src
*** Upravljanje z okni
Navigacijo med okni izvajamo s klasičnimi HJKL UNIX smernimi tipkami, recimo okno pod trenutnim izberemo s ~SPC w j~. Posamezno okno pa lahko razdvojimo vertikalno ali horizontalno s ~SPC w v~ oz. ~SPC w s~. ~SPC w d~ "ubije" trenutni buffer in okno.
#+begin_src emacs-lisp
(start/leader-keys
"w" '(:ignore t :wk "window")
"w j" 'windmove-down
"w k" 'windmove-up
"w h" 'windmove-left
"w l" 'windmove-right
"w s" 'split-window-below
"w v" 'split-window-right
"w d" 'kill-buffer-and-window)
#+end_src
*** Upravljanje z bufferji
TODO napiši navodila
#+begin_src emacs-lisp
(defun nalozi-konfiguracijo () (interactive) (find-file "~/.emacs.d/config.org"))
(start/leader-keys
"b" '(:ignore t :wk "buffer")
"b b" 'switch-to-buffer
"b p" 'previous-buffer
"b n" 'next-buffer
"b e" 'eval-buffer
"b s" (defun scratch-buffer () "Show scratch buffer" (interactive) (switch-to-buffer "*scratch*"))
"b c" 'load-config
"b d" 'kill-current-buffer
"b k" 'kill-buffer)
#+end_src
*** Evalviranje
TODO napiši navodila
#+begin_src emacs-lisp
(add-to-list 'kategorije-bliznjic (lambda ()
(start/leader-keys
;; EVAL ukazi
"e" '(:ignore t :wk "eval")
"e b" 'eval-buffer
"e e" 'eval-expression
"e r" 'eval-region)))
#+end_src
*** Datoteke
TODO napiši navodila
#+begin_src emacs-lisp
(add-to-list 'kategorije-bliznjic (lambda ()
(start/leader-keys
"f" '(:ignore t :wk "file")
"f f" 'counsel-find-file
"f c" 'load-config)))
#+end_src
*** Vplogled / introspekcija
Emacs nudi kup uporabnih funkcij, ki so nepogrešljive na poti učenja o funkcionalnosti. Zaenkrat sem definiral bližnjice do štirih od njih; opis funkcije, tipke, simbola (to so recimo rezervirana imena spremenljivk), načina (~mode~).
#+begin_src emacs-lisp
(add-to-list 'kategorije-bliznjic (lambda ()
(start/leader-keys
"d" '(:ignore :t :wk "describe")
"d f" 'describe-function
"d k" 'describe-key
"d s" 'describe-symbol
"d m" 'describe-mode)))
#+end_src
*** Konec
Dodamo manjkajoči zaklepaj. :)
To pa je malo grdo pri pismenem programiranju.
#+begin_src emacs-lisp
)
#+end_src
** Zaključek

View File

@ -1,112 +1,5 @@
;;;;;;;;;;;
;; DEBUG ;;
;;;;;;;;;;;
;; Debagiraj napake?
;(setq debug-on-error t)
;; Make startup faster by reducing the frequency of garbage
;; collection.
(setq gc-cons-threshold (* 50 1024 1024))
;; Prikaz statistik nalozenih paketov (prikazi z M-x use-package-report)
;(setq use-package-compute-statistics t)
;;;;;;;;;;;;
;; PAKETI ;;
;;;;;;;;;;;;
;; Loudamo melpa paketice (in pa ORG)
(require 'package)
(setq use-package-always-ensure t) ;; always ensures that a package is installed
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
(add-to-list 'package-archives '("elpa" . "https://elpa.gnu.org/packages/") t)
(package-initialize)
(use-package benchmark-init
:config
;; To disable collection of benchmark data after init is done.
(add-hook 'after-init-hook 'benchmark-init/deactivate))
;;;;;;;;;;
;; EVIL ;;
;;;;;;;;;;
(setq evil-want-integration t
evil-want-keybinding nil)
;org-return-follows-link t
(require 'evil)
;; Evil mode toggle <3
(evil-mode 1)
(use-package general
:config
(general-evil-setup)
;; Leader key nastavitev (za prozenje ukazov)
(general-create-definer start/leader-keys
:states '(normal insert visual emacs)
:keymaps 'override
:prefix "SPC" ;; set leader
:global-prefix "C-SPC") ;; access leader in insert mode
(defun load-config () (interactive) (find-file "~/.emacs.d/init.el"))
(start/leader-keys
;; Osnovne bliznjice
"[" 'previous-buffer
"]" 'next-buffer
;; WINDOW ukazi
"w" '(:ignore t :wk "window")
"w j" 'windmove-down
"w k" 'windmove-up
"w h" 'windmove-left
"w l" 'windmove-right
"w s" 'split-window-below
"w v" 'split-window-right
"w d" 'kill-buffer-and-window
;; BUFFER ukazi
"b" '(:ignore t :wk "buffer")
"b b" 'switch-to-buffer
"b p" 'previous-buffer
"b n" 'next-buffer
"b e" 'eval-buffer
"b s" (defun scratch-buffer () "Show scratch buffer" (interactive) (switch-to-buffer "*scratch*"))
"b c" 'load-config
"b d" 'kill-current-buffer
"b k" 'kill-buffer
;; EVAL ukazi
"e" '(:ignore t :wk "eval")
"e b" 'eval-buffer
"e e" 'eval-expression
"e r" 'eval-region
;; FILE ukazi
"f" '(:ignore t :wk "file")
"f f" 'counsel-find-file
"f c" 'load-config
;; Vpogled / introspekcija
"d" '(:ignore :t :wk "describe")
"d f" 'describe-function
"d k" 'describe-key
"d m" 'describe-mode))
;; Dodatne evil bližnjice
(use-package evil-collection
:after evil
:config
(evil-collection-init))
;; Naloži konfiguracije iz ORG datoteke
(org-babel-load-file "~/.emacs.d/config.org")
;;;;;;;;;
;; GUI ;;
@ -263,7 +156,15 @@
(company-mode))
;; LSP potrebuje dependency iz npm: "sudo npm install -g vue-language-server
(use-package lsp-mode :defer t)
(use-package lsp-mode
:defer t
:config
;; Pospešimo
;; Make gc pauses faster by decreasing the threshold.
(setq gc-cons-threshold (* 100 1000 1000))
;; Increase the amount of data which Emacs reads from the process
(setq read-process-output-max (* 1024 1024)) ;; 1mb
)
;; Vuejs moud
(use-package vue-mode
@ -481,6 +382,7 @@
'(("^ *\\([-]\\) "
(0 (prog1 () (compose-region (match-beginning 1) (match-end 1) ""))))))
;; Drugačne pisave za naslove, svoje velikosti
;; Vir: https://zzamboni.org/post/beautifying-org-mode-in-emacs/
(let* ((variable-tuple
(cond ((x-list-fonts "ETBembo") '(:font "ETBembo"))
((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
@ -488,11 +390,11 @@
((x-list-fonts "Verdana") '(:font "Verdana"))
((x-family-fonts "Sans Serif") '(:family "Sans Serif"))
(nil (warn "Cannot find a Sans Serif Font. Install Source Sans Pro."))))
;(base-font-color (face-foreground 'default nil 'default))
(base-font-color "#FF0000")
(base-font-color (face-foreground 'default nil 'default))
(headline `(:inherit default :weight bold :foreground ,base-font-color)))
(custom-theme-set-faces
'user
`(org-level-8 ((t (,@headline ,@variable-tuple))))
`(org-level-7 ((t (,@headline ,@variable-tuple))))
`(org-level-6 ((t (,@headline ,@variable-tuple))))
@ -501,12 +403,22 @@
`(org-level-3 ((t (,@headline ,@variable-tuple :height 1.25))))
`(org-level-2 ((t (,@headline ,@variable-tuple :height 1.5))))
`(org-level-1 ((t (,@headline ,@variable-tuple :height 1.75))))
`(org-document-title ((t (,@headline ,@variable-tuple :height 2.0 :underline nil)))))))
`(org-document-title ((t (,@headline ,@variable-tuple :height 2.0 :underline nil))))))
;; DOT diagrami
(org-babel-do-load-languages
'org-babel-load-languages
'((dot . t)))
;; ditaa diagrami
(org-babel-do-load-languages
'org-babel-load-languages
'((ditaa . t))))
;; Evil orgmode
(use-package evil-org
:after org
:hook (org-mode . 'evil-org-mode)
:hook (org-mode . (lambda () (evil-org-mode)))
:general
(start/leader-keys
;; ORGmode ukazi
@ -534,8 +446,7 @@
;; Šminka za naslove
(use-package org-bullets
:after org
:config
(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))))
:hook ((org-mode . (lambda () (org-bullets-mode 1)))))
;; Lepsi fonti
(setq org-src-fontify-natively t)
@ -581,16 +492,6 @@
;; Zacnimo na ponedeljek, kot se spodobi
(setq calendar-week-start-day 1)
;; DOT diagrami
(org-babel-do-load-languages
'org-babel-load-languages
'((dot . t)))
;; enable ditaa (diagrami)
(org-babel-do-load-languages
'org-babel-load-languages
'((ditaa . t)))
;; Mermaid v orgmode (diagrami)
(use-package ob-mermaid
:defer t
@ -911,10 +812,5 @@
'(org-level-8 ((t (:inherit default :weight bold :foreground "#ebdbb2" :family "Sans Serif")))))
;; Make gc pauses faster by decreasing the threshold.
(setq gc-cons-threshold (* 10 1000 1000))
;; Increase the amount of data which Emacs reads from the process
(setq read-process-output-max (* 1024 1024)) ;; 1mb
;; supercollider mode load
;(require 'sclang)

View File

@ -94,6 +94,7 @@ ln -s $DIR/applications/arduino2.desktop ~/.local/share/applications/arduino2.de
# Emacs <3
mkdir ~/.emacs.d
ln -s $DIR/.emacs.d/init.el ~/.emacs.d/init.el
ln -s $DIR/.emacs.d/config.org ~/.emacs.d/config.org
ln -s $DIR/.emacs.d/projectile-bookmarks.eld ~/.emacs.d/projectile-bookmarks.eld
ln -s $DIR/.emacs.d/bookmarks ~/.emacs.d/bookmarks