Dot Emacs

.emacs

Use the template below for .emacs

Visual Line Mode

Whenever you open a text file, automatically switch to visual line mode (i.e. wraparound). This avoids having to select Options | Line Wrapping in this Buffer | Word Wrap from the menu every time you open a new file that you want to do some writing in.

And turn off electric indent mode. I will handle my own indentation just fine, thank you.

(add-hook 'text-mode-hook #'visual-line-mode)

(electric-indent-mode -1)

CUA Mode

Turn on CUA mode. This allows one to use the familar C-c/C-v for cut and paste. Except in the wsl terminal where C-v seems to be difficult to override. Best workaround I have so far is to map M-v instead.

Also, I tend to have names of other files in my org file. It is convenient to have a keyboard shortcut to go there directly.

(cua-mode)


(global-set-key '[(f12)] 'copy-region-as-kill)
(global-set-key '[(f9)] 'yank)

(global-set-key (kbd "M-c") 'copy-region-as-kill)
(global-set-key (kbd "M-b") 'cua-paste)

(global-set-key (kbd "C-<f1>") 'find-file-at-point) 


Shell Command

Like one of the most basic things I do in an org mode elisp source block is call shell functions. The macro sh! helps with this. And if you are doing aws s3 cli commands, s3! saves some typing. You have to set up the aws cli separately, this doesn't help with that.



(defmacro sh! (it) `(shell-command-to-string ,it) )
(defun s3! (it) (sh! (concat "aws s3 " it)))

Some nice characters

These are some characters that I like access to.

  • ¿ English really should start questions with the upside-down question mark the way that Spanish does. Change my mind.
  • Ч The cyrillic CH character is so useful when abbreviating words that have a ch in them
  • π pi, for when you want to talk about the ratio of the circumference of a circle to its diameter
  • Π product, for when you want to abbreviate the word product, as in Π manager, Π owner, ..
  • λ



(defun q! () (interactive) (insert-char #xbf))
(defun ch! () (interactive) (insert-char #x427))
(defun pi! () (interactive) (insert-char #x3c0))
(defun PI! () (interactive) (insert-char #x3a0))

(defun lambda! () (interactive) (insert-char #x03bb))
(defun -> () (interactive) (insert-char #x2192))
(defun <- () (interactive) (insert-char #x2190))


Org file

Call org! when creating a fresh org file.

Yes, I could add a parameter to this to give it a name but I don't find it onerous to just cursor up and change the name manually.

  • toc:nil Don't need no stinkin' table of contents
  • num:nil Headers look better when not adorned with unnecessary ordinality
  • html-postamble:nil Don't give me that silly author/created/validate stuff at the bottom. Keep my footer unadorned too.
  • stylesheet in HTML head. Use a full URL rather than a relative path. It saves trouble when shuffling things through different directories.

But if you are creating an org file for use with beamer, you need a whole set of special options to make things nice.


(defun org! () (interactive) (insert "#+title: Org File                                                            
#+author:  Omega Prime  
#+options: toc:nil
#+options: num:nil 
#+OPTIONS:  html-postamble:nil
#+HTML_HEAD: <link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.omega-prime.pictures/scribble.css\">
") )







(defun beamer-org! (n) (interactive "s:  ")
       (insert "#+title:  ")
       (insert n)
(insert "
#+author:  Isaac Newton
#+options: toc:nil
#+options: num:nil
#+startup: beamer
#+LaTeX_CLASS: beamer
#+LaTeX_CLASS_OPTIONS: [bigger]
#+LATEX_HEADER: \\usepackage{geometry}
#+LATEX_HEADER: \\geometry{ papersize={13.33in, 7.5in}, left=0.5in, top=0.25in, right=0.5in, bottom=0.25in, headsep=.5in  }

#+LATEX_HEADER: \\usepackage{pagecolor}
#+LATEX_HEADER: \\usepackage{lipsum}
#+LATEX_HEADER: \\usepackage{fancyhdr}
#+LATEX_HEADER: \\pagestyle{fancy}
#+LATEX_HEADER: \\fancyhead{}
#+LATEX_HEADER: \\fancyhead[R]{}
#+LATEX_HEADER: \\fancyhead[L]{}
#+LATEX_HEADER: \\fancyfoot{}
#+LATEX_HEADER: \\setbeamertemplate{navigation symbols}{}

#+LATEX_HEADER: \\definecolor{iblue}{RGB}{0, 17, 65}
#+LATEX_HEADER: \\pagecolor{iblue}
# LATEX_HEADER: \\pagecolor{black!70!blue}
#+LATEX_HEADER: \\setbeamercolor{normal text}{fg=white}
#+LATEX_HEADER: \\setbeamercolor{titlelike}{fg=white}
#+LATEX_HEADER: \\setbeamercolor{block title}{fg=white}
#+LATEX_HEADER: \\setbeamercolor{part name}{fg=white}
#+LATEX_HEADER: \\setbeamercolor{section name}{fg=white}
#+LATEX_HEADER: \\setbeamercolor{subsection name}{fg=white}
#+LATEX_HEADER: \\setbeamercolor{item}{fg=white}
#+LATEX_HEADER:  \\usefonttheme{structurebold}
#+LATEX_HEADER: \\setbeamercolor{alerted text}{fg=blue!20!white}

#+LATEX_HEADER: \\institute{  }


#+MACRO:  beamercolumn_begin  #+LATEX:  \\begin{columns}[t] \\begin{column}{$1\\textwidth}
#+MACRO:  beamercolumn_mid    #+LATEX:  \\end{column}    \\begin{column}{$1\\textwidth}
#+MACRO:  beamercolumn_end    #+LATEX:  \\end{column}    \\end{columns}

"))




Aliai

some of my faviorite shell aliases that i like to use.




alias ll='ls -l'
alias ramdrive='sudo mount -t tmpfs -o size=2g tmpsfs /mnt/rmdrv'

alias weather='curl wttr.in/London?n'

alias c='clear && '
alias cg='clear && pwd && git '
alias cgs='cg status'



alias cc='ncal -w -A '

alias t2='tree -L 2'
alias lb='clear && pwd && git branch -a'
alias lc='ls -l --color=never'
alias gs='cd ~/Documents/git-source'
alias doupgrade='sudo apt update && sudo apt upgrade -y'

Llama.cpp


./server -m models/wizardlm-13b-v1.2.Q4_K_M.gguf -c 2048 --host 0.0.0.0

HTML

One of the main things I do with the org file is generate html.

This is just a macro that allows you to do M-x hhtml instead of C-x C-s C-c C-e h o which is the manual org export command to generate and open an html file. But that is 6 keystrokes either way! you cry. Yes, but if you are doing repeated exports, as you write and edit your file, the next time its just M-x cursor up, return. Which importantly saves cognitive load in addition to key strokes.

So set F8 key as a shortcut just in case as well.

The other things I might want to do is genearate a pdf in portrait mode. M-x latex is the equivalent for that.

If I am in a landscape mood with my .pdf, then beamer is just the thing, so I can use M-x beamer

[Usually this is because expectations at work are for a slideshow when a (prose, portrait) report would be better, but that is a different issue.!]



(fset 'hhtml
      (kmacro-lambda-form [?\C-x ?\C-s ?\C-c ?\C-e ?h ?o] 0 "%d"))

(global-set-key '[(f8)] 'hhtml)


(fset 'latex
   "\C-x\C-s\C-c\C-ell")

(fset 'beamer
   "\C-x\C-s\C-c\C-elb")


Babel

Add the appropriate languages for babel.

And stop prompting me on execution every time. I am going to be evalating these a lot.


(setq org-plantuml-jar-path (expand-file-name "data_/plantuml.jar"))
;(add-to-list 'org-src-lang-modes '("plantuml" . plantuml))
(org-babel-do-load-languages
 'org-babel-load-languages
 '((plantuml . t))) ; this line activates plantuml
(org-babel-do-load-languages
 'org-babel-load-languages
 '((latex . t)))
(org-babel-do-load-languages
 'org-babel-load-languages
 '((R . t)))
(org-babel-do-load-languages
 'org-babel-load-languages
 '((dot . t))) ; this line activates dot
(org-babel-do-load-languages
 'org-babel-load-languages
 '((awk . t)))
(org-babel-do-load-languages
 'org-babel-load-languages
 '((shell . t)))

(require 'ox-beamer)


(setq org-confirm-babel-evaluate nil)


Beamer

Some helper functions for when writing beamer files.


(defun org/image-width (w n) (interactive "sWidth (em)?  \nsName?  ")
       (insert "#+ATTR_LATEX:  :width ")
       (insert w)
       (insert "em
[[file:pix_/")
       (insert n)
       (insert ".png]]")
       )

(defun bmr/columns () (interactive)
       (insert "{{{beamercolumn_begin(0.38)}}}

{{{beamercolumn_mid(0.62)}}}

{{{beamercolumn_end}}}

") )





(defun put-cols! () (interactive) (insert "
#+LATEX:  \\begin{columns}
#+LATEX:  \\begin{column}{0.5\\textwidth}
  LHS
#+LATEX:  \\end{column}
#+LATEX:  \\begin{column}{0.5\\textwidth}
  RHS
#+LATEX:  \\end{column}
#+LATEX:  \\end{columns}
"))


(defun put-pix! (n) (interactive "s:  ")
 (insert "
#+CAPTION:  ")
(insert n)
(insert "
[[file:pix_/")
(insert n)
(insert ".png]]
")
)

(defun pix-width! (n) (interactive "s:  ")
       (insert "#+ATTR_LATEX:  :width ")
       (insert n)
       (insert "em
")
       )


Graphwiz

Some helper functions for editing graphwiz files.



(defun llabel (s0) (interactive "s?  ")
(insert "[label=< <b>")
(insert s0)
(insert "</b>  <br/>  .. > ]
")
)


(fset 'make-gw-url
   "\C-[OF [label= <\C-[[3~ <b> \C-[OF </b> > URL=\"\C-[[3~\C-[OF\C-[OF\"[\C-?]\C-m"
)


#+ENDSRC





(defun babel-graphviz (the-name) (interactive "s?  ") (insert "
#+BEGIN_SRC dot :file pix_/")
(insert the-name)       
(insert ".svg :cmdline -Kdot -Tsvg

digraph G {

node [style=filled fillcolor=\"#EEEEEE\"]  

rankdir = BT

A -> B

}

#+end_src
"))

Eel

The all important eel function. First thing to do after creating a file and calling M-x org! is to add an '* Eel :noexport' section and then call M-x eel On my system this resovles unambiguously to eelisp. So I get a babel block that I can put elisp in.





(defun eelisp () (interactive) (insert "

  #+BEGIN_SRC elisp :exports both

(setq x0 93)

x0


  #+END_SRC 

"))





If you have to do python, you can change :exports both to :results output

Sun

A bash script to get the time of sunset in London. For places other than London, if those still exist, change the default values in the script or pass new latitude, longitude and timezone in as parameters.

  • Use https://api.sunrise-sunset.org/api
  • Read it with duckdb ; you will need to have duckdb installed
  • Extract just the sunset time from the json with duckdb
  • Thanks to my best friend, Claude, for helping me with the code.
  • Place this in $PATH and chmod u+x sun (assuming the bash file is named sun)
#!/bin/bash

# Default values for London
default_lat="51.5074"
default_lon="-0.1278"
default_tz="Europe/London"

# Use provided values or defaults
lat=${1:-$default_lat}
lon=${2:-$default_lon}
tz=${3:-$default_tz}

# Remove the minus sign from longitude if present
lon=${lon#-}

# Execute the DuckDB command
duckdb -c "select sunset from (select unnest(results) from read_json_auto('https://api.sunrise-sunset.org/json?lat=$lat&lng=-$lon&tzid=$tz'));"

Then you can just type sun at the command line and get the current sunset time.


└─$ sun
┌────────────┐
│   sunset   │
│  varchar   │
├────────────┤
│ 7:07:05 PM │
└────────────┘

Because of course thats what you want to know right? You have an alarm for sunset on your phone. Oh, you mean not everyone does? Yeah, I knew that.