JWen's Blog

Personal website of JWen 丁文亮的个人网站

Notes of Emacs Lisp


With the support of these powerful tools, I believe I am able to overcome the barrier of knowledge and have the freedom to pursue what I really want (doing research while less subjected to the presure of life).

Jul 18 - 23, 2024

To learn Emacs Lisp, I started reading the GNU Emacs Lisp Reference Manual, which was suggested by Andy Stewart in his blog. As a newbie, I dreaded this manual pouring too much dry notations to me without any toy application or practice. Maybe I took a wrong reading method to it, as I did find it helpful when I searched for some Emacs built-in variables or functions from the website. Anyway, I stop at Sec 2.4.5 and turn to the YouTube series Learning Emacs Lisp by System Crafters. At least his first video teach me treating the elisp code as data (in a list form) to be sent to the interpreter. I will take notes of these video first and maybe back to the manual in the future.

Meanwhile, after dropping by the Quick Start of use-package and so many Emacs config on Github (e.g. Purcell’s and Ian’s), I started to transform my Emacs config into “use-package” version1. Before then, my Emacs had heavy loaded packages I dunno and various code blocks copied from here and there. Now I know exactly why I want to use these packages and how to settle them down in a neat way. This change brings me lots of benefits. First, search information from official website or high-quality blogs of the package you are interested in, instead of from various second-hand and low-quality resources. Second, keep asking question and find your own taste. I always wonder which is better for me, Helm or Ivy? I find Switching from Helm to Ivy from Google and From helm, to ivy from DuckDuckGo, and both of them are adopted in my current Emacs config. Now I use Ivy for almost all of the completion and remain Helm installed for the basic helm-apropos C-x c a.

Jul 25, 2024

Pull all-nighters working on the problem of company-20240719.2038 installed from MELPA. Problem solved by replacing the MELPA’s company with the GNU ELPA’s version company-0.10.2. I met the problem, that completion works well at the beginning and suddenly don’t when the typed content becomes long (around 3 lines…), when I edited this org. The problem still occur if I re-start the EMacs. I spent 2-3 hours searching the solution but failed, and the idea of using GNU ELPA’s version instead of MELPA’s came to my mind when I laid on the bed (remained awake, staring to the ceiling). Therefore, I re-install all the packages that are available on the GNU ELPA, and only turn to MELPA if the former has too many warnings (e.g. use smartparens-20240713.1002 from MELPA).

Now all features I temporarily need have settled down. It’s time to stop configuring and start preparing for TOEFL.

Jul 31, 2024

I’m learning elisp. Following the tutorial of creating symbolic link, I am confused about the symbolic link created by

(make-symbolic-link "~/.../.dotfiles/.files/.config/guix"
                    "~/.../demo-output/.config/guix")

Because such symbolic link displays ugly in my Dired with color dired-broken-symlink, and if I visit it, the Message buffer tells me

dired-get-file-for-visit: File is a symlink to a nonexistent target

After several mins of searching in Google, including StackExchange, StackOverflow etc, I finally find these website useless and solve the problem by myself through reading the help page of make-symbolic-link. Note that M-x make-symbolic-link works (“It works” level, we can’t use M-x in elisp script). Then I find the best solution from the Manual.

;; (make-symbolic-link "~/.dotfiles/.config/guix" "~/.config/guix")
;; ;; Error if exists
;; (make-symbolic-link "~/.dotfiles/.config/guix" "~/.config/guix" t)
;; ;; No error!

;; M-x make-symbolic-link is okay

(make-symbolic-link "~/dotfiles/.files/.config/guix"
                    "~/Desktop/research/learn/elisp/demo-output/.config/guix2" 1)
;; OK, see C-h f make-symbolic-link
;; An integer third arg means request confirmation if LINKNAME already
;; exists, and expand leading "~" or strip leading "/:" in TARGET.
;; This happens for interactive use with M-x.

(make-symbolic-link "~/dotfiles/.files/.config/guix"
                    "~/Desktop/research/learn/elisp/demo-output/.config/guix3")
;; dired-get-file-for-visit: File is a symlink to a nonexistent target

(make-symbolic-link "~/dotfiles/.files/.config/guix"
                    "~/Desktop/research/learn/elisp/demo-output/.config/guix4" t)
;; dired-get-file-for-visit: File is a symlink to a nonexistent target

(make-symbolic-link "~/dotfiles/.files/.config/guix"
                    "~/Desktop/research/learn/elisp/demo-output/.config/guix5" 5)
;; OK

(make-symbolic-link "/Users/jwen/dotfiles/.files/.config/guix"
                    "~/Desktop/research/learn/elisp/demo-output/.config/guix6")
;; OK, Error if exists

(make-symbolic-link "/Users/jwen/dotfiles/.files/.config/guix"
                    "~/Desktop/research/learn/elisp/demo-output/.config/guix6" t)
;; OK, No error!

(make-symbolic-link "/:~/dotfiles/.files/.config/guix"
                    "~/Desktop/research/learn/elisp/demo-output/.config/guix7" t)
;; OK, No error!
;; see https://www.gnu.org/software/emacs/manual/html_node/emacs/Copying-and-Naming.html
;; see https://www.gnu.org/software/emacs/manual/html_node/emacs/Quoted-File-Names.html
;; You can quote an absolute file name to prevent special characters and syntax
;; in it from having their special effects. The way to do this is to add ‘/:’ at
;; the beginning.

This story tells us what a great program and community would look like. They offer you useful information on the HelpPage and Manual. Everytime you meet problems you can rely on these information and try to solve the problems on your own, with courage and prudence.

This story also tells us how important the taste is. For a programing language with poor Help information and unfriendly community, studying it is just a waste of life. You would spend lots of time but benefit a little.

Todo

  1. C++
  2. Python
    • Using Emacs as a Python IDE
  3. Org
  4. Yasnippet

  1. Admittedly, skimming Emacs config is still time-consuming. Without the bedrock of Elisp, I can only put simple and theme-related packages to my config, e.g. emacs-configuration => MatthewZMD’s .emacs.d => Doom Modeline. I have to remind myself that “doom-modeline”-type packages do make me in a good mood but do not have much to do with my productivity. ↩︎