A super cool method to set the configuration of emacs, following DistroTube
Emacs requires tweaking the init.el
file in the .emacs.d
dir in home
init.el
is written in emacs-lisp and a bit obscure to understand
One can use the wonderful emacs org-mode
to code the init.el
by using an auxiliary config.org
placed in any directory
The steps are described below (generated by emacs org-mode)
In addition to set a proper configuration, it also useful to use emacs as a client, which speeds up running emacs.
This is done, first running the emacs daemon
/usr/bin/emacs --daemon
And then any time we launch emacs we use
emacsclient -c -a 'emacs'
In Linux systems, the emacs daemon can be launched at startup by adding the service to the systemd
as detailed here
Table of Contents
1 How to configure emacs by a emacsconfig.org file
1.1 Set your init.el in .emacs.d
Write the following init.el in .emacs.d
(org-babel-load-file
(expand-file-name
"~/org/emacsconfig.org"
user-emacs-directory))
Here emacsconfig.org is the org configuration file with its path You can set any file
In this file we have various functions
- Org Babel
Org Babel is a wonderful tool to use different languages in a single org file
- org-babel-load-file
Loads Emacs Lisp source blocks in the org file
- expand-file-name
Replace the file name with absolute path
- user-emacs-directory
Is the directory where the Emacs-specific files are placed .emacs.d typically, where the search of the file starts
1.2 Write emacsconfig.org
In the .org file for the configuration we will write different parts as pieces of emacs lisp code. For example
* FRAME SIZE #+begin_src emacs-lisp (add-to-list 'default-frame-alist '(width . 180)) (add-to-list 'default-frame-alist '(height . 90)) #+end_src * FONTSIZE #+begin_src emacs-lisp (set-face-attribute 'default (selected-frame) :height 150) #+end_src
Emacs Lisp (nano) cheat sheet
Invoke function (C-x C-e
to evaluate)
(f x0 x1)
(f x0 x1 x2)
Function definition
(defun my-fun (x0 x1)
"function description"
(+ x0 x1))
Lambda function
(setq my-f (lambda (x y) (+ x y)))
(funcall my-f 1 2)
Setting variables, with quote is the name of the variable(setq x y)
is equivalent to (set (quote x) y)
(setq name "nautilus")
(setq name value)
'x ;; is the name of x, not the value (like the pointer in C)
'(a b c) ;; is a list
(setq x '(0 1 2 3)) ;; x is a list
Emacs, latex, and all that
GNU Emacs is great, superfun
You can play a lot with things like latex, and org-mode, and coding in emacs
I use emacs in windows and linux systems
Windows 10 WSL
I was used to the windows version of emacs 25 in windows 10, but WSL is a supernice tool, thus I recently switched to WSL Ubuntu 20.04, and installed emacs27 via the PPA repository. You may install the APP ubuntu 20.04 in Windows Store. See this post
In windows 10 new need a good X10 server for opening windows, I found that X410 works nicely (it is not freeware)
You need to modify your .bashrc
and add
DISPLAY=localhost:0
export DISPLAY
The windows filesystem in the ubuntu WSL terminal is automatically mounted in /mnt/c/Users/
To install emacs27 in ubuntu 20.04 WSL
sudo add-apt-repository ppa:kelleyk/emacs
sudo apt update
sudo apt install emacs27
Ubuntu 20.04
Same as above, works fine
My emacs configuration
As for many Linux things, the nice feature in emacs and all that is that you can easily configure anything. The problem is that you may become addicted in continuously changing the settings, because you do not like the window size, the font, etc. The good news is that this is also true in emacs!
To configure emacs you can either change the file .emacs
, whic you can put or find in your home directory. Or you may change the file .emacs.d/init.el
where .emacs.d
is a config directory that is also in the home. The two methods are exclusive, meaning that either you use .emacs
, or .emacs.d/init.el
. I prefer to used .emacs.d/init.el
as it is more recent.
For example, if you want to change the font, you have to put the following line in .emacs.d/init.el
(set-face-attribute 'default (selected-frame) :height 100)
This may seem weird, as it is not something like fontsize=12, but it is a glimpse into the supersmart world of Lisp. Indeed emacs is written in Lisp, a proper Lisp, the “emacs-lisp” and that is the reason why emacs is so cool.
to be continued
emacs, auctex, Sumatra.pdf in Windows 10
On Windows 10 Pro
Install MiKTeX from https://miktex.org/
Download emacs zip file in the GNU mirror. I have chosen in http://mirror.lihnidos.org/GNU/ftp/gnu/emacs/windows/ the file in the folder emacs-26 http://mirror.lihnidos.org/GNU/ftp/gnu/emacs/windows/emacs-26/emacs-26.3-x86_64.zip
Unzip the emacs file in some folder for example Downloads folder, you will have a folder with name emacs-26.1-x86.4
Inside this emacs folder, click on runemacs
Now emacs is running, but you need to install auctex and Sumatra.pdf. You may create a shortcut to runemacs in the application bar by right clicking on it
To install auctex open emacs, then “M+x package-install auctex” and hit return
M+x package-install auctex
Sumatra.pdf enables to open multiple windows with the same pdf file. Acrobat blocks the compilation if the pdf is open.
Install Sumatra.pdf from https://www.sumatrapdfreader.org
Sumatra.pdf exe file will be in “C:\Program Files\SumatraPDF”
C:\Program Files\SumatraPDF
Now you need to configure emacs for using Sumatra.pdf, this is done by modifying the .emacs file
The .emacs file is the main configuration file for emacs
You find the .emacs file in the folder “C:\Users\<USER>\AppData\Roaming”
C:\Users\YourUserNameHere\AppData\Roaming
This is a hidden folder, you need to enable showing hidden folder in windows explorer (go to options in the folder menu)
Open .emacs and add the lines at the end of the file and save
(setq TeX-PDF-mode t) (setq TeX-source-correlate-mode t) (setq TeX-source-correlate-method 'synctex) (setq TeX-view-program-list '(("Sumatra PDF" ("\"C:/Program Files/SumatraPDF/SumatraPDF.exe\" -reuse-instance" (mode-io-correlate " -forward-search %b %n ") " %o")))) (eval-after-load 'tex '(progn (assq-delete-all 'output-pdf TeX-view-program-selection) (add-to-list 'TeX-view-program-selection '(output-pdf "Sumatra PDF"))) ) (server-start)
Now you are set to run auctex in emacs with forward search and Sumatra.pdf