emacs
;; -*- mode: emacs-lisp -*- ;; ;; -- init.el: emacs config ;; ;; ;; -- built in ;; (require 'package) (add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t) (package-initialize) (setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3") (setq inhibit-splash-screen t) (appt-activate t) (savehist-mode t) ;; dired (put 'dired-find-alternate-file 'disabled nil) (setq delete-by-moving-to-trash t) ;; hippie expand (global-set-key (kbd "M-/") 'hippie-expand) (setq hippie-expand-try-functions-list '(try-expand-dabbrev try-expand-dabbrev-all-buffers try-expand-dabbrev-from-kill try-complete-file-name-partially try-complete-file-name try-expand-all-abbrevs try-expand-list try-expand-line try-complete-lisp-symbol-partially try-complete-lisp-symbol)) ;; ido (require 'ido) (setq ido-enable-flex-matching t) (setq ido-everywhere t) (ido-mode t) ;; eww (setq browse-url-browser-function 'eww-browse-url) (setq browse-url-generic-program "dillo") ;; (setq eww-search-prefix "https://wiby.org/?q=") ;; org (org-babel-do-load-languages 'org-babel-load-languages '((calc . t) (shell . t) (gnuplot . t) (python . t) (R . t) (C . t))) ;;(setq org-html-validation-link nil) (setq org-log-done t) (setq org-agenda-files (list "~/Documents/writing/webpage/org/toread.org")) ;;(add-hook 'org-mode-hook (lambda () (variable-pitch-mode t))) ;; gnus (gnus-delay-initialize) ;; add time stamp when sending email (setq message-draft-headers '(References From)) ;; push out queued emails every 60 minutes (gnus-demon-add-handler 'gnus-delay-send-queue 60 nil) (gnus-demon-init) (require 'bbdb) (setq bbdb-north-american-phone-numbers-p nil) (setq bbdb-user-mail-names (regexp-opt '("i.oezgen@tu-braunschweig.de"))) ;; cycling while completing email addresses (setq bbdb-complete-name-allow-cycling t) (setq bbdb-use-pop-up nil) ;; ;; -- custom functions ;; (load "~/.emacs.d/elisp/custom-functions.el") ;; ;; -- third party library ;; (require 'pdf-tools) (require 'ebib) ;; ;; -- append automatic configurations ;; (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(custom-safe-themes (quote ("169070e358960ebebe946874fa55c109e37d57868500bc288b3946892f023e23" default))) '(ebib-bib-search-dirs (quote ("~/PowerFolders/Ilhan/reading"))) '(ebib-file-associations (quote (("pdf") ("ps")))) '(ebib-file-search-dirs (quote ("~/PowerFolders/Ilhan/reading"))) '(ebib-notes-directory "/home/ilhan/PowerFolders/Ilhan/notes/sources/") '(ebib-preload-bib-files (quote ("library.bib"))) '(ebib-reading-list-file "~/Documents/writing/webpage/toread.org") '(fci-rule-color "#f8fce8") '(hl-paren-background-colors (quote ("#e8fce8" "#e1faff" "#f8e8e8"))) '(hl-paren-colors (quote ("#005500" "#1054af" "#880000"))) '(package-selected-packages (quote (bbdb org-tree-slide ebib pdf-tools htmlize ess))) '(sml/active-background-color "#e1faff") '(sml/active-foreground-color "#444444") '(sml/inactive-background-color "#1054af") '(sml/inactive-foreground-color "#444444")) ;;(custom-set-faces ;; ;; custom-set-faces was added by Custom. ;; ;; If you edit it by hand, you could mess it up, so be careful. ;; ;; Your init file should contain only one such instance. ;; ;; If there is more than one, they won't work right. ;; '(variable-pitch ((t (:family "Liberation Serif")))))
Notes on emacs
Just use ed(1).
If you need to work with multiple files and don't want to use ed, gnu emacs is a nice editor with a graphical user interface.
When using emacs, it is sometimes advised to launch it as a daemon
with server-start
and to keep it running for the entire session.
This allows you to open other files from the command line through
the emacsclient
command. Files will open in the emacs window that
is already open.
However, I prefer to start a single emacs instance and use eshell
inside it. The advantage of eshell
over your operating system's
terminal emulator is that files can be opened directly with C-f
.
Other emacs keybindings are also consistent inside eshell
.
The emacs manual
The emacs manual is very good. Within emacs, it can be evoked from
everywhere by executing C-h r
. It this doesn't work, it's probably
not installed. In debian, it can be installed through apt install
emacs-common-non-dfsg
.
Useful functionalities
emacs comes with many useful built-in functionalities, which are well-documented in the aforementioned manual. Additional functionalities can be added through external repositories.
org mode
org mode is a plain text note taking system with a rich ecosystem.
Hippie Expand
When activated, Hippie Expand provides low-overhead
auto-completion, based on text in open buffers. Start typing a
word, and then invoke auto-completion with M-/
. Hippie Expand
completes the word by cycling through different auto-completion
mechanisms that can be specified in the configuration file—see
below. If the correct expansion of the word has been passed by
accident, use C-/
to cycle back.
Keyboard macros
emacs lets you record and re-execute any chain of commands, which
are called keyboard macros. We use C-x (
to start and C-x )
to end the recording. Once recorded, the macro can be executed
repeatedly through C-x e
. This is useful if the same action has
to be performed repeatedly throughout the text and there is no good
regular expression to capture. It allows for a more general
structural editing than the regular expression-based workflow in,
for example, ed(1).
apply-macro-to-region-lines
runs the keyboard macro on each line
in the region. I also sometimes just execute the macro a specific
[number]
of times via C-[number] C-x e
.
Gnus
gnus is a news and email reader that ships with emacs. It lets you subscribe to email inboxes and, for example, RSS feeds.
gnus hides emails that have been read. To view these older
emails, use /o
, which displays all email. Login credentials are
stored in $HOME/.authinfo
.
- De- and encryption
gnus can de- and encrypt emails using GnupPG. See this section of the manual for more details. If the key is setup with the corresponding email address, emacs encrypts and decrypts emails without the need for further configuration. Emails are encrypted via
C-c C-m c o
. Decryption works automatically, if you receive an encrypted message and you have the correct key added to your keyring. - Address book
An address book to store e-mail addresses can be managed using the Insidious Big Brother Database (bbdb), see the manual FAQ entry. The package can be installed from the gnu repository via the emacs package manager. Once it is installed, it needs to be configured in the
.gnus.el
andinit.el
files as shown in the next section.Start the address book on its own via
M-x bbdb
and leave the regex field empty. This lists all entries. New entries can be added viac
(create). Add all addresses you want and close bbdb withq
(quit).Now, when writing an email and filling out the address, bbdb will suggest contacts and cycle through them in another buffer.
- Delay email sending
Gnus can schedule emails to be sent at a certain time. This requires the following line in
init.el
:(gnus-delay-initialize) (setq message-draft-headers '(References From)) (gnus-demon-add-handler 'gnus-delay-send-queue 60 nil) (gnus-demon-init)
The second line ensures the correct time stamp. The last two lines set up a demon to automatically push out queued messages every 60 min. In a message buffer, press
C-c C-j
instead ofC-c C-c
. The message is put into a folder calleddelayed
.
Dired
dired is a file browser that is shipped with emacs that can be
invoked through M-x dired
.
Selecting multiple files
Navigate in the directory holding the files you want to search in.
Using m
, mark all files you want to modify.
If there are too many files to mark by hand, one can execute M-x
find-dired
and then provide suitable flags, such as -name
"*.cpp"
. This opens another dired buffer with the files that
match the regex. If you want to select all matches, press t
,
which toggles marks.
Replacing regular expression in several files
In dired, we can replace a regular expression across several
files. Select multiple files as described above. Following the
manual entry on the subject, execute
dired-do-find-regexp-and-replace
or, alternatively, press Q
.
Follow the instructions. The files need to be explicitly saved.
pdf-tools
pdf-tools is a suite to view and modify pdf files. In my opinion, it works better than the built-in doc-view, which relies on converting pdf files into png files. It can be installed through the package-manager from melpa.
If you only occasionally view pdf documents with emacs you don't need this package.
ebib
ebib is a BibTeX reference manager for emacs, written by J. Kremers. It can be installed through the emacs repository melpa. It has been recommended to me by Göktuǧ Kayaalp on mastodon.
ebib is very straight-forward to use. One thing I struggled with was to export individual entries. Göktuǧ provided an answer:
In the top buffer you can hit
C e
to copy the selected entry's bibtex. Alsox
is for export, it prompts for a database name (i.e. a bibtex file opened in ebib, open files witho
, creates.bib
file if it doesn't exist, close database withc
). You can also mark withm
and do bulk export. Sadly it doesn't visibly indicate marked entries by default so it's a bit difficult to work with marks.
Underrated functionalities
remember
saves the current selection to.emacs.d/notes
calendar
gives you calendar functionalities, where you can take notes and schedule appointmentsgnus
provides email and rss reader functionalitieseww
is a really good text-based web browser that can display imageseshell
is an alternative shell with elisp supporttab-line-mode
andglobal-tab-line-mode
provide tab functionalities- See also the article Batteries included with emacs and the follow-up More batteries included with emacs
Notes
(setq default-directory (concat (getenv "HOME") "/"))
sets default directory to the home directory(setq initial-buffer-choice "~/.emacs.d/scratch.org")
sets the initial buffer when emacs starts(set-face-attribute 'default nil :height 110)
sets the font size- When using
(setq delete-by-moving-to-trash t)
on MacOS, emacs moves deleted files to~/.local/share/Trash
instead of MacOS's Trash. Just avoid MacOS if possible. (add-hook 'org-mode-hook (lambda () (variable-pitch-mode t)))
activates variable pitch fonts in org buffers(find-file "/home/ilhan/.emacs.d/notes")
opens a file at start up
The best resource to look stuff up is the official manual. A good curated list of articles and news can be found at Planet Emacslife.
See also:
- Comfortably edit C with emacs by P. Kaludercic (mirror)
- Emacs F90 mode quick reference by J. Blevins
- Emacs org-mode examples and cookbook by E.H. Neilsen, Jr.