187 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Org Mode
		
	
	
	
	
	
			
		
		
	
	
			187 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Org Mode
		
	
	
	
	
	
| * How To Use
 | |
| 
 | |
| #+begin_src sh :results output scalar
 | |
| cp -r <USB_MOUNT> ~/.emacs.d
 | |
| chown -R <YOUR_USER> ~/.emacs.d
 | |
| # ln -sf <THIS_REPO> ~/.emacs.d
 | |
| #+end_src
 | |
| 
 | |
| * Introduction
 | |
| 
 | |
| *"Original" EMACS:*
 | |
| - 1976
 | |
| - David A. Moon & Guy L. Steele Jr.
 | |
| - Set of macros for the TECO editor (char based editor)
 | |
| 
 | |
| *Gosling Emacs:*
 | |
| - 1981
 | |
| - James Gosling (the Java® guy)
 | |
| 
 | |
| *GNU Emacs:*
 | |
| - 1984
 | |
| - Richard Stallman aka. [[http://stallman.org/saint.html][Saint IGNUcius]] /(saint in the Church of Emacs)/
 | |
| 
 | |
| *Latest Release*: Emacs 30.1
 | |
| *Released:* February, 2025
 | |
| 
 | |
| Emacs uses ~emacs-lisp~:
 | |
| - lisp dialect
 | |
| - functional (not pure though)
 | |
| - specially developed to configure Emacs
 | |
| 
 | |
| ** Variables
 | |
| 
 | |
| #+begin_src emacs-lisp :results output scalar
 | |
| (defvar my/var nil "My very own variable")
 | |
| (setq my/var "Hey Emacs!")
 | |
| (print my/var)
 | |
| ;; There are more... (setq-local, setq-default)
 | |
| #+end_src
 | |
| 
 | |
| #+RESULTS:
 | |
| : "
 | |
| : \"Hey Emacs!\"
 | |
| : "
 | |
| 
 | |
| ** Functions
 | |
| 
 | |
| #+begin_src emacs-lisp :results output scalar
 | |
| (defun test ()
 | |
|   "Docstring"
 | |
|   (interactive)
 | |
|   (print my/var))
 | |
| 
 | |
| (test)
 | |
| #+end_src
 | |
| 
 | |
| #+begin_src emacs-lisp :results output scalar
 | |
| (defun more (a b &optional c d &rest e)
 | |
|   (interactive)
 | |
|   ; 'a 'b 'c 'd '(...)
 | |
|   (print (concat a b c d (mapconcat #'identity e ""))))
 | |
| 
 | |
| (more "1" "2" "3" "4" "5" "6" "7")
 | |
| (more "1" "2" "3")
 | |
| #+end_src
 | |
| 
 | |
| #+RESULTS:
 | |
| : "
 | |
| : \"1234567\"
 | |
| :
 | |
| : \"123\"
 | |
| : "
 | |
| 
 | |
| #+begin_src emacs-lisp :results output scalar
 | |
| (defun print-name (&rest args)
 | |
|   (interactive)
 | |
|   (let ((first (plist-get args :first))
 | |
|         (last (or (plist-get args :last) "?")))
 | |
|     (princ last)
 | |
|     (when first
 | |
|       (princ ", ")
 | |
|       (princ first))))
 | |
| 
 | |
| (print-name :first "Philip" :last "B1")
 | |
| #+end_src
 | |
| 
 | |
| #+RESULTS:
 | |
| : "B1, Philip"
 | |
| 
 | |
| ** Let Bindings
 | |
| 
 | |
| #+begin_src emacs-lisp :results output scalar
 | |
| (defun another-test (a b)
 | |
|   "Multiplies `A' times `B' and adds them afterwards"
 | |
|   (interactive)
 | |
|   (let* ((x a)
 | |
|          (y (* x b)))
 | |
|     (+ x y)))
 | |
| 
 | |
| (print (another-test 2 4))
 | |
| #+end_src
 | |
| 
 | |
| #+RESULTS:
 | |
| : "
 | |
| : 10
 | |
| : "
 | |
| 
 | |
| ** Hooks
 | |
| 
 | |
| #+begin_src emacs-lisp :results output scalar
 | |
| (defun my/fun () (message "Emacs is cool!"))
 | |
| (add-hook 'after-save-hook #'my/fun)
 | |
| ;; (remove-hook 'after-save-hook 'my/fun)
 | |
| #+end_src
 | |
| 
 | |
| ** Package Management & Configuration
 | |
| 
 | |
| *Package Manager*
 | |
| - https://github.com/radian-software/straight.el
 | |
| 
 | |
| #+begin_src emacs-lisp :results output scalar
 | |
| ; Standard is package.el
 | |
| (straight-use-package 'nix-mode)
 | |
| #+end_src
 | |
| 
 | |
| #+RESULTS:
 | |
| : ""
 | |
| 
 | |
| *Configuration Macro*
 | |
| - https://github.com/jwiegley/use-package
 | |
| 
 | |
| #+begin_src emacs-lisp :results output scalar
 | |
| (straight-use-package 'use-package)
 | |
| 
 | |
| ;; Macro that provides syntactic sugar
 | |
| (use-package color-moccur
 | |
|   ;; Creates autoloads for these commands
 | |
|   ;; Defers loading of the module until command is used
 | |
|   :commands (isearch-moccur isearch-all)
 | |
|   ;; Keybindings
 | |
|   :bind (("M-s O" . moccur)
 | |
|          :map isearch-mode-map
 | |
|          ("M-o" . isearch-moccur)
 | |
|          ("M-O" . isearch-moccur-all))
 | |
|   ;; Before package is loaded
 | |
|   :init
 | |
|   (setq isearch-lazy-highlight t)
 | |
|   ;; After package is loaded
 | |
|   :config
 | |
|   (use-package moccur-edit))
 | |
| #+end_src
 | |
| 
 | |
| ** Tour de Emacs Config
 | |
| 
 | |
| .emacs.d/
 | |
| ├── early-init.el
 | |
| ├── init.el
 | |
| └── cnf/
 | |
|     ├── app
 | |
|     └── lang
 | |
| 
 | |
| ** Tasks
 | |
| *** Keybinding
 | |
| 
 | |
| - Create a new keybinding for the ~emacs-lisp-mode~ that executes ~eval-last-sexp~ with the binding ~SPC x e~ while in ~normal~ mode
 | |
| 
 | |
| **** Possible Solution
 | |
| 
 | |
| #+begin_src emacs-lisp :results output scalar
 | |
| (my-leader
 | |
|   :keymaps 'emacs-lisp-mode-map
 | |
|   :states 'normal
 | |
|   "x" '(:ignore t :which-key "Eval")
 | |
|   "x e" 'eval-last-sexp
 | |
|   "x b" 'eval-buffer)
 | |
| #+end_src
 | |
| 
 | |
| *** Package
 | |
| 
 | |
| - Install a new package using straight, e.g. ~swiper~ (or something else)
 | |
| 
 | |
| **** Possible Solution
 | |
| 
 | |
| #+begin_src emacs-lisp :results output scalar
 | |
| (straight-use-package 'swiper)
 | |
| #+end_src
 | 
