Emacs

Enable Jupyter in Doom Emacs

tech emacs

There are a few adjustments needs for the default installation when using the jupyter package in Emacs. Here’s a step-by-step guide to configure it properly with Doom Emacs.

Step 1: Install the jupyter package.

Add this line to package.el:

(package! jupyter)                      ;

Step 2: Enable builtin Jupyter Support in Org Mode

To enable Jupyter support in Org mode, make the following modifications in your init.el file:

  1. Uncomment the ein line. The emacs-ipython-notebook is a dependency of jupyter package.
  2. Add +jupyter to the Org settings. For more details, refer to :lang org:
(org +jupyter)               ; organize your plain life in plain text

Step 3: Patch for Runtime Errors with ZeroMQ

To address a runtime error related to ZeroMQ (as discussed in this issue), append the following code to your config.el or any other configuration file:

Emacs Lisp Introduction for Python Programmers

emacs lisp tech python

This is a brief introduction to Emacs Lisp for Python programmers, (although I am not an Elisp expert, and actually I am more familiar with Python than Elisp). Both languages have quite different syntaxes, it is interesting to see how can implement Python code with lisp code.

The content follows the strucutre from Learn X in Y Minutes Where X is Python, and we will touch all the topics.

Primitive Datatypes and Operators

Numbers

Python

# Integer
1
# Float
3.14
# Math is what you would expect
1 + 1   # => 2
8 - 1   # => 7
10 * 2  # => 20
35 / 5  # => 7.0

# Integer division rounds down for both positive and negative numbers.
5 // 3       # => 1
-5 // 3      # => -2
5.0 // 3.0   # => 1.0  # works on floats too
-5.0 // 3.0  # => -2.0

# The result of division is always a float
10.0 / 3  # => 3.3333333333333335

# Modulo operation
7 % 3   # => 1
# i % j have the same sign as j, unlike C
-7 % 3  # => 2

# Exponentiation (x**y, x to the yth power)
2**3  # => 8

# Enforce precedence with parentheses
1 + 3 * 2    # => 7
(1 + 3) * 2  # => 8
Elisp

;; Integer
1
;; Float
3.14
;; Math is what you would expect
(+ 1 1)   ; => 2
(- 8 1)   ; => 7
(* 10 2)  ; => 20
(/ 35 5)  ; => 7

;; Integer division rounds down for both positive and negative numbers.
(truncate (/ 5 3))       ; => 1
(truncate (/ -5 3))      ; => -2
(truncate (/ 5.0 3.0))   ; => 1.0  ; works on floats too
(truncate (/ -5.0 3.0))  ; => -2.0

;; The result of division is always a float if the denominator or numerator is float
(/ 10.0 3)  ; => 3.3333333333333335

;; Modulo operation
(% 7 3)   ; => 1
;; different from Python
(% -7 3)  ; => -1

;; Exponentiation
(expt 2 3)  ; => 8

;; Enforce precedence with parentheses
(+ 1 (* 3 2))    ; => 7
(* (1+ 3) 2)  ; => 8

Bools and comparasion

In Emacs Lisp, booleans are represented by the symbols t for true and nil for false.

Emacs Essentials

emacs tech

It is a steep learning curve to master Emacs lisp, there are mainly two issues in it from my experience

  1. the lisp syntax and functional programming
  2. the fragmented methods and libraries

For the 1st issue, it is easy to master the syntax after writing several programs and getting used to them, but for the 2nd one, one needs to take notes or remember something.

In this blog, I focus on the 2nd point and keep updating the notes of some methods and libraries that I think are essential for writing Emacs lisp packages.