Towards Freedom

Information, Inspiration, Imagination
truly a site for soaring Is


Various topics and aids for emacs

WHERNTO: techniq  operate 

image of Emacs

Emacs Items


use this to get colors since shell doesn't give it don't use term because it requires C-c C-j to go into line mode

this code runs ansi-term without the zsh prompt

;; use ansi-term with zsh
(defun zterm ()
  "term to use zsh"
  (ansi-term "zsh"))

daemon as systemd

$ systemctl –user enable –now emacs cp usr/lib/systemd/user/emacs.service .config/systemd/user systemctl enable –user emacs

default editor


edit directories with emacs


C-x d from eshell or provide a pattern!

  C-x (4|5) d ~/
  C-x d ~/*
  C-x d ~/.*
  C-x d ~/D*
  C-x d ~/**/*.el ;globstar should work but doesn't
  C-x (4) C-j if done in dired gives parent dir


j <==> C-x C-f
M-s f (M-)C-s searches just for filename (or change dired-isearch-filenames to t)


DEL doesn't work
d,u,x does (on regions too)
m,D is an alternative

multiple flagging

#,~,. probably not going to use
% & don't understand??
% d regexp very nice!!

toggle hidden files

C-u s and -al -> -l or may be this [][Toggle Showing Dot Files]

visiting files

v readonly view

not same as openwith which can be done in various ways, but simplest for now is M-! <app> file.
this isn't as convenient as nnn, but should do for now. dired+ apparently has a way to do this.

visit dir

use a instead of C-m to discard ancestors use C-x C-j to jump to parent (but that will leave trail), so go to .. and use a

dired marks and flags

these offer many possibilities, but are awkward to remember right now.

  m can do region or C-u N as well
  * N number and size of files in marked region
  * * mark exe files
  * @ mark slinks
  * s mark all in dir
  * / mark dirs
  U remove all marks

  mark by regexp
  % m
  % d
  % g
  some of these may be useful though we can't see why right now:\\
  * t toggle
  M-{} move up/down to next marked file
  C-/ undo dired changes
  * c old new: * c D t  * c SPC D  * c t SPC

operating on files

C new
R new to existing dir (dired-create-destination-dirs)
S new

A regexp very nice!!
Q regexp very nice!!

% u,l upper,lower case filenames

probably not useful at this stage
M modespec
G newgroup
O newowner

transforming filenames

% R,C,H,S computes new name by regexp doing a search-replace not sure how important this is since we can treat the dir as emacs buffer


C-u k

find and locate

these are done from dired

M-x find-name-dired
M-x locate

view images

C-t d on marked image files
M-x image-dired

rotations possible with jpegtran

delete and tag of image files also possible, so can this replace gthumb??

other features

M-x dired-create-empty-file
M-x dired-compare-directories
M-s a C-s isearch on filenames


index mechanism

trying to figure out how to search the feeds from .elfeed in data/1d/1da2ce0dd6436d802f0e1b35ad60f8b745780a5b in index "" nil) ("" . "") #s(elfeed-entry ("" . "") "Elasticity to position microplates on curved 2D fluids" "" 1617649345.0 #s(elfeed-ref "1da2ce0dd6436d802f0e1b35ad60f8b745780a5b") html nil (unread)

emailing a buffer

C-ret to setup email C-M-p to prger

setup init-elfeed

use variable for feeds remove titles, but set them as tags (setq aiblog <URL>) though we did have (setq aiblog (list <URL> <TITLE)) title now "" and set as a tag

regex group replacement

(car aiblog) -> aiblog (car \(......\)) -> \1


some of these items apply to emacs in general.


occur <regex> displays matching items in history

cd =, cd =foo, cd -N are excellent for moving into directories!

sudo works using eshell/sudo, but as an alias (eshell-prefer-lisp-functions didn't work)

built-in variables:
$+, $-, $$, $? (with ending underscores), may be useful for scripting
also, note specific args handling with $*, $1, $2 …

eshell to have $PATH

;; match zshenv PATH (setenv "PATH" (shell-command-to-string "echo -n $PATH"))

that seems a lot simpler (not sure if it will work either), however, we did it another way by

  • echo $PATH > tmp
  • edit tmp
  • PATH=$(cat tmp)

after the above in zsh, we go to eshell and

  • (setq path <copied from echo $PATH>)
  • (setq exec-path (split-string path ":"))


  (setq var "this is a string with extension.test")
  $'var' disambiguate
  $#var length

  $(sexp) can be used in a string
  ${cmd} output of cmd
  $<cmd> output to tmpfile

  $var[i] ith element of sequence (string split on spc)
  $var[: n0 n1 n2 ...] split on : ;interpolation into larger string ??
  $var["\\\\" i] ;??
  $var["[0-9]+" 10 20] ;??
  $var[hello] ;??
  $#var[hello] ;??

fix the history!! issue

customize eshell-expand-input-functions by INS eshell-expand-history-references t

for loop

  for VAR in TOKENS { command invocation(s) }
  for i in (split-string
            (shell-command-to-string "cat /etc/passwd") "\n")
      {(print (string-join (list i "BOO") " "))}


help on function at point: C-h f


M-p|n works as expected

M-r|s is a bit awkward compared to C-r in regular shell, though there may be a better way

unlike C-r in a regular shell, M-r doesn't keep cycling back … need to figure out how to deal with this

TODO pcomplete

not sure what this is completion concept


mostly same as zsh, but we also have these neat items

  >>> #<buffer-name>
  - > /dev/clip

as well as being able to define virtual targets with ("/dev/name" function mode)


use source from eshell and eshell-source-file from rest of emacs

ssh to remote

C-x C-d /ssh:lentil: M-x eshell and it works perfectly!

sudo issue

which sudo give /usr/bin/sudo - even when lisp functions are prefered ??!! so we use an alias sudo eshell/sudo $* apparently the documentation is misleading

alias sff find-file /sudo::$1

ess and paredit

these two don't play nicely and you get c () so remove paredit from .R files and things seem to be just fine


fetch and deliver mail it is MDA which can fetch simple config for our notmuch purposes

following symbolic links

C-h v vc-follow-symlinks and change the value this will handle git asks when opening a file



doesn't handle C-c C-a synopsis unless there is a blank line macro fynopsis takes care of this and is bound this way: (add-hook 'fountain-mode-hook ; enters synopsis for screenplain issue (lambda () (local-set-key (kbd "C-c C-a") 'fynopsis)))


xpdf -open

this works quite well until it is unable for some reason to create a remote socket. however, the problem can be nullified by: rm /tmp/default which removes the socket process (i guess?) unfortunately, when operating as a server, the textedit:// feature does not work as effectively though you still get the line number of where you want to go to in the .ly file.

xpdf setup (works with mupdf too, but not llpp or evince)

issues with compilation pdf view and midi playback in conflict


the idea will be to use search/tag rather than folders to get things done


%notmuch setup -> ~/.notmuch-config used to have .emacs.d/notmuch-config.el with mainly the Q binding, but that is now in init-email.el


emacs -e "notmuch" with client it used to be different: emacsclient -e "(elfeed)" -e "(notmuch)" & emacsclient -c ~/aa/ &

various commands

search|show|address|count reply tag dump|restore config


wildcards using '*' operators +|-|AND|NOT|XOR|OR| brackets proximity NEAR ADJ phrases "Debian Project" <=> Debian ADJ/1 Project prefix freeform idea, but uses full item eg from: instead of f: range date:yr-mo-da..yr-mo-da | | yesterday

man notmuch-search-terms

fetch/trash mechanism

use f|c|p|t

  1. files are left on server but not duplicated
  2. fdm fetch will remove them from server
  3. polls
  4. trash require 'S' on emails then t moves them to ~/.trash

be careful using c) because if you read using spark or whatever on the server and leave the item as read, then using this removes them from the server, but we're not sure where the email actually goes! yes we are now!!

we must be sure that we are running nmp from ~/ otherwise mail/ will be created wherever we are!

autocomplete email addresses

chose to use bbdb and use bbdb-vcard with contacts.vcf exported from google Go to, click the menu "Export…>>vCard format (blah, blah …)". Click "Export" button. Download the contacts.vcf. Make sure bbdb-vcard.el installed. In Emacs run "M-x bbdb-vcard-import-file" and input the full path of contacts.vcf In Emacs run "M-x bbdb-save" Import Gmail contacts into BBDB

gnus-alias to select identity didn't set rules use M-x gnus-alias-select-identity

external handlers for attachments

w - to save the attachment - though the default doesn't always seem to work. . o allows reading the item provided you specify the type

sending email

evolution removals

for some reason, the setup for smtp wasn't being picked up in the init.el file and that is why evolution kept coming up. instead of smtpmail-send-it the setting had changed to mailclient-send-it. this is nice to know in case we should ever require it in the future.

;; smtp (setq smtpmail-default-smtp-server "" send-mail-function 'smtpmail-send-it user-full-name "prad" smtpmail-local-domain "" user-mail-address "") (require 'smtpmail)

otherwise it defaults to evolution because gnome sets it, though we can change it to notmuch through settings.

vivaldi mail issue

however, what is the problem replying to vivaldi? no issues sending to vivaldi or replying to any other place it seems. changing the smtp to "" sent, but still the same problem with replying to vivaldi!

<2021-06-21 Mon> we are sending emails through because shawmail wouldn't send (even though it appeared to do so).

2 items noted:

  1. gnus alias setup is sufficient (no need for msmtp) ("tf" nil ;; Does not refer to any other identity "prad <>" ;; Sender address "" ;; Organization header (("X-Message-SMTP-Method" . "smtp 587")) nil ;; extra body text "~/.signature") ("fm" ;;formal tf nil "prad basu <>" "prad basu" ;; Organization header (("X-Message-SMTP-Method" . "smtp 587")) nil ;; No extra body text "~/") ("vv" nil "prad <>" "prader" ;; Organization header (("X-Message-SMTP-Method" . "smtp 587")) nil ;; No extra body text "~/.signature.vv") )
  2. mail-host-address (setq mail-host-address "localhost") couldn't figure out how to change it via smtp on gnus-alias, but that's probably not important however, we need this to prevent Message ID <87lf72na5y.fsf@schnell.i-did-not-set–mail-host-address–so-tickle-me> doing ("Message-ID" . "") didn't work though it did get the item in there. receiving end produced: Message ID <>

still getting a spf softfail: send from vivaldi -> tf reply from tf -> vivaldi don't know why, but it probably doesn't matter.

also unclear why .authinfo required vivaldi smtp info but nothing for tf



org macros

github link The macros in Org allow you to add text or code to an Org document that will be expanded during export: the text between the 3 pairs of accolades is expanded so that readers can see it in the exported versions of the document.

Some people (such as me) use it to construct complex HTML or LaTeX code.

13.5 Macro Replacement


update packages

M-x list-packages and it will automatically refresh the archive contents.

Then, press U to mark all upgradable packages to be upgraded.

Last, press x to perform the new updates.

Emacs will then download and install all upgradable packages. It will also ask you whether to delete the old packages: M-x package-autoremove


Option 2: The profiler

  1. Invoke M-x profiler-start RET RET (the second RET is to confirm cpu);
  2. Do some typing, preferably an entire paragraph or more;
  3. Invoke M-x profiler-report.

That will give you a buffer describing the cpu time taken by each function. Hitting TAB on a line expands it to display the functions inside it. Navigate this buffer until you find out which function is taking so much CPU time.

we tried this to figure out AC mode was slowing things down, but we already knew that. Not sure what to do about it though.


hanging with ssh put in the remote .zshrc [[ $TERM == "dumb" && unsetopt zle && PS1='$ ' this seems to be a zsh issue because people have said that when the switch to bash it all works.

ssh with sudo

C-x C-f /ssh:psinom|sudo:psinom:<FILE>

variable void

shell-mode-map is a variable that is defined in the file shell.el which is not loaded yet, so the variable is undefined.

(require 'shell) before you try use the variable. post


issue with [I ] on first word

we don't really know what the problem is. it occurs with emacs -nw, but not with sudo emacs -nw solution which works is to use emacs -nw -Q

enter giving Wrong type argument: stringp, nil

inserting the doc with C-x C-i didn't work hopefully copying the items one by one will we will also leave orgmode to its own file

close help window without going to it

(setq help-window-select t) that way when using q, it closes the help window since it is already there.

read-only toggle

C-x C-q

block commenting trick

we don't really need this since emacs is setup with C-M-c and C-M-S-c for comments

: '
This is a 
very neat comment
in bash
echo "This is outside the commented block"

Executing the above code would result in: This is outside the commented block