/emacs-modules

Modules I coded myself for emacs

Primary LanguageEmacs LispGNU General Public License v3.0GPL-3.0

Emacs modules/modes

These are my personal collection of emacs modes and modules I have written with custom functions to help make my workflow better.

Basic description

FileModuleShort Description
mtl-edit.elMTL edit modeA minor mode for editing Machine translated outputs.
remind-mode.elRemind modeMajor mode for editing remind script files.
calt-mode.elCalt modeA minor mode to parse and calculate expression while in text mode.
litex-mode.elLiTeX modeA minor mode to convert valid elisp expressions to LaTeX.

Long Description

MTL-Edit mode

Here is a demo video. It shows mainly the features of mtl mode but does a bit of other scripts in the beginning and the end. The linked timestamp is or mtl mode.

[https://youtu.be/plr_tdNSdtM?t=317]

Remind mode

This is to edit remind files, there isn’t much here except for basic syntax highlighting to differentiate the keywords and comments and such.

Calt mode (Calculation Template Mode)

This mode was created because I needed some org-babel code blocks like functionality for my LaTeX document but while being inside the LaTeX. It’s just single line code/expressions with support for templates.

The evaluation is done in a python subprocess, hence you can assign variables and then reuse them. Except for the first line in the equation array, other lines are generated from the template in the comments.

% <<a=46.1;>>
% <<b=46.4;>>
% <<c=47.9;>>
% <<d=45.8;>>
% <<e=46.8;>>
% <<f=48.6;>>
% <<g=48;>>
% <<h=47.7;>>
% <<i=50.6;>>
% <<import math;>>

\begin{eqnarray*}
  S_x &=& \frac{(a+2*d+g)-(c+2*f+i)}{8\Delta}\\
  % S_x &=& \frac{<<(a+2*d+g);.1f>>-<<(c+2*f+i);>>}{80}\\
  % S_x &=& \frac{<<(a+2*d+g)-(c+2*f+i);.1f>>}{80}\\
  % S_x &=& <<s_x=((a+2*d+g)-(c+2*f+i))/80;>><<s_x;.4f>>\\
  S_x &=& \frac{185.7-195.7}{80}\\
  S_x &=& \frac{-10.0}{80}\\
  S_x &=& -0.1250\\
  S_y &=& \frac{(g+2*h+i)-(a+2*b+c)}{8\Delta}\\
  % S_y &=& \frac{<<(g+2*h+i);.2f>>-<<(a+2*b+c);.2f>>}{80}\\
  % S_y &=& \frac{<<(g+2*h+i)-(a+2*b+c);.2f>>}{80}\\
  % S_y &=& <<s_y=((g+2*h+i)-(a+2*b+c))/80;>><<s_y;.4f>>\\
  S_y &=& \frac{194.00-186.80}{80}\\
  S_y &=& \frac{7.20}{80}\\
  S_y &=& 0.0900\\
  S &=& \sqrt{S_x^2+S_y^2}\\
  % S &=& \sqrt{<<s_x*s_x;.4f>>+<<s_y*s_y;.4f>>}\\
  % S &=& \sqrt{<<s_x*s_x+s_y*s_y;.4f>>}\\
  % S &=& <<s = math.sqrt(s_x*s_x+s_y*s_y);>><<s;.4f>>\\
  % S^\circ &=& \tan^{-1}(<<s;.4f>>) = <<math.atan(s)*180/math.pi;.2f>>^\circ\\
  % Aspect &=& <<a=math.atan2(s_x,s_y);>><<a;.3f>> = <<a*180/math.pi;.2f>>^\circ
  S &=& \sqrt{0.0156+0.0081}\\
  S &=& \sqrt{0.0237}\\
  S &=& 0.1540\\
  S^\circ &=& \tan^{-1}(0.1540) = 8.76^\circ\\
  Aspect &=& -0.947 = -54.25^\circ
\end{eqnarray*}

LiTeX mode

Moved to: [https://github.com/Atreyagaurav/litex-mode]. Now available in melpa.

This is a minor mode to convert valid elisp/lisp expressions to latex.

This is useful for emacs users because emacs allows lisp code to be directly evaluated inside any buffer, which means no need to have any code blocks. But since lisp expressions aren’t popular we can’t expect to put them in reports, so to overcome that I wrote this mode with the help of my friend Bibek Panthi.

Suppose we have this in a text file, we have all the variables and the formula as lisp expressions.

Net radiation, (setq R_n 185) W/m²
Temperature, (setq T 28.5) °C
Relative Humidity, (setq Rh .55)
Air velocity at 2m height, (setq u_2 2.7) m/s
Atmospheric pressure, (setq p 101.3e3) Pa
Roughness height, (setq Z_0 0.03) cm
(setq Z_2 200) cm

Energy balance method:
(setq E_r (/ (- R_n H_s G) l_v ρ_w))
 
Where,
(setq l_v (- 2500 (* 2.36 T))) kJ/kg
(setq l_v (* l_v 1e3)) J/kg
From table 2.5.2
(setq ρ_w 996.4) kg/m³

Assume, (setq H_s 0 G 0)
(setq E_r (/ (- R_n H_s G) l_v ρ_w))

After evaluating all expressions, we can get the values, while we can also convert them to latex format like this:

Net radiation, R_n = 185 W/m²
Temperature, T = 28.5 °C
Relative Humidity, Rh = 0.55
Air velocity at 2m height, u_2 = 2.7 m/s
Atmospheric pressure, p = 1.01 \times 10^{5} Pa
Roughness height, Z_0 = 0.3 cm
Z_2 = 200 cm

Energy balance method:
E_r = \frac{R_n - H_s - G}{l_v ρ_w }
 
Where,
l_v = 2500 - 2.360 T  = 2500 - 2.360 \times 28.500  = 2500 - 67.260 = 2432.74 kJ/kg
l_v = l_v \times 1000  = 2432740.0 J/kg
From table 2.5.2
ρ_w = 996.400 kg/m³

Assume, H_s = 0; G = 0
E_r = \frac{R_n - H_s - G}{l_v ρ_w } = \frac{185 - 0 - 0}{2432.740 \times 996.400 } = \frac{185}{2432.740 \times 996.400 } = 7.63 \times 10^{-05}

So not only can it convert lisp expressions to latex, it can also, give intermediate solution steps. Perfect for doing homeworks (as that’s what I made it for) :P

Improvement over Calt-mode:

./images/litex.png

Configuration

Clone the repo into your machine and add the path to load-path, or just load the individual module you want to add.

Sample configuration using use-package I use is as follows:

(use-package mtl-edit-mode
  :load-path "~/.emacs.d/myfunc/"
  :commands mtl-edit-mode
  :init (bind-key "C-x /" 'mtl-edit-mode)
  )

(use-package calt-mode
  :load-path "~/.emacs.d/myfunc/"
  :commands calt-mode
  :hook text-mode
  :config (local-set-key (kbd "C-e") calt-key-map)
  )