From e437fddbabc800d4fd2342f2da3934d11668ac14 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Sun, 4 Dec 2022 21:59:31 +0000 Subject: [PATCH] Finish up episode 12 --- docs/videos.org | 77 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/docs/videos.org b/docs/videos.org index d0bc837..8127542 100644 --- a/docs/videos.org +++ b/docs/videos.org @@ -1,4 +1,4 @@ -#+TITLE: How to build an editor with Emacs Lisp +#+TITLE: Emacs From Scratch - An Emacs tutorial for beginners #+SEQ_TODO: TODO(t/!) NEXT(n/!) BLOCKED(b@/!) | DONE(d%) CANCELLED(c@/!) FAILED(f@/!) #+TAGS: READER(r) MISC(m) #+STARTUP: logdrawer logdone logreschedule indent content align constSI entitiespretty overview @@ -628,7 +628,8 @@ CLOSED: [2022-11-04 Fri 15:25] ** Real Examples Let's discuss ~defflag~ and ~when-flag~ macros in [[file:../core/fg42/flags.el]] -* Episode 11 - Common pitfalls of Macros +* DONE Episode 11 - Common pitfalls of Macros +CLOSED: [2022-12-04 Sun 12:15] ** Compiletime vs runtime #+BEGIN_SRC emacs-lisp ;; `do-something-with-side-effect' evaluates on compile time @@ -704,3 +705,75 @@ Never evaluate the arguments of a macro manually. E.g. with =eval= More info: https://www.gnu.org/software/emacs/manual/html_node/elisp/Eval-During-Expansion.html ** What's next? +* Episode 12 - Features & Load Paths +** Emacs Lisp files +Write elisp code in files with =.el= suffix. + +*** Batch mode +Execute an elisp file via Emacs in a non-interactive (script like) fashion: + +#+BEGIN_SRC bash +emacs --batch -l /path/to/the/file +#+END_SRC + +*** =load= function +Loads an elisp file into the running Emacs process. For more info ~C-h f load~. +#+BEGIN_SRC emacs-lisp + (load "/path/to/the/file") + (load "PATH1") +#+END_SRC + +- It first looks for the =PATH + .elc= combination +- If not successful, looks for the =PATH + .el= combination +- If not successful, looks for platform dependent suffixes +- If not successful, tries to load the =PATH= as it is + +** Load Path +*** =load-path= +List of directories to search for files to load. + +#+BEGIN_SRC emacs-lisp + (add-to-list 'load-path "/path/to/a/directory") +#+END_SRC + +*** =EMACSLOADPATH= environment variable + +** Emacs =feature= +Emacs tracks loaded packages and file via =features=. Each elisp file can =provide=, zero or +more =features=. + +Features are just symbols. + +*** =features= list +A list of all loaded features. For more info, try ~C-h v features~. + +*** =featurep= +A predicate function to check whether a feature is loaded or not. + +#+BEGIN_SRC emacs-lisp + (featurep 'some-feature) +#+END_SRC + +*** =provide= + +#+BEGIN_SRC emacs-lisp + (provide 'some-feature) +#+END_SRC + +*** =require= +If the given feature as the parameter is not loaded yet, loads it via the =load= +function. For more info, ~C-h f require~. + +#+BEGIN_SRC emacs-lisp + (require 'some-feature) + + ;; Or + + (require 'some-feature "/path/to/file") +#+END_SRC + +** Installing Emacs packages the hard way +We can clone a library somewhere on the disk and add the path to it to the =load-path= list +and load the library files. + +But that would be tedious to do so for all the libraries. That's why we use a package manager