Created: 2019-10-04 Mon 00:31
simon.tournier@univ-paris-diderot.fr
2011 New Year Resolutions: Switch to Emacs (video)
\(\Rightarrow\) because the sysadmin showed me crazy stuff
&& he helped me to start.
I am only an enthusiast user, not a guru
(defun ask-at-point (&optional i-know)
"Feel free to ask everything."
(interactive "P")
(if i-know (message "Quick Answer.")
(browse-url
(concat "https://www.ddg.gg/?q=emacs+" (thing-at-point 'symbol)))))
Emacs is a User Interface (UI) to manipulate text
All what X is able, Emacs does it too.
Proof: Let as an exercise after this presentation.
Start Emacs
Initial release: 1976; 42 years ago (timeline)
"Buffer" hold the content of a file
"Open a file" means open a buffer that "visits" that file
C-x C-f means
press Control and x then Control and f
M-x means press Alt and x
Copy | C-w |
Paste | C-y |
Cut | M-w |
Find | C-s |
Find-Replace | M-% |
@simon: check your cheatsheet :-)
"Habit is habit, and not to be flung out of the window by any man, but coaxed downstairs a step at a time." – Mark Twain
describe-key | C-h k |
describe-function | C-h f |
describe-mode | C-h m |
… | … |
isearch-forward | C-s |
find-file | C-x C-f |
set-mark | C-SPC |
kill-ring-save | M-w |
kill-region | C-w |
yank | C-y |
… | … |
I DO NOT recommand CUA-mode (windows-like shortcuts)
Muscle one small step after another
The configuration is driven by
$HOME/.emacs.d/init.el
Set variables
;; to see the life in colours
(global-font-lock-mode 1)
;; to remove the icons bar
(tool-bar-mode 0)
;; what?!? who use the latteral bar to scroll ? :-)
(scroll-bar-mode 0)
Set other variables
;; remove the initial starting message
(setq inhibit-startup-message t)
;; delete the *scratch* initial message
(setq initial-scratch-message nil)
@simon: quick demo-it
Conditional set
;; remove the menu when inside terminal
(if (display-graphic-p)
(menu-bar-mode 1)
(menu-bar-mode 0))
Rename commands
;; simplify the question-answer process
(defalias 'yes-or-no-p 'y-or-n-p)
;; M-x mode-* instead of the long name
(defalias 'mode-whitespace 'whitespace-mode)
(defalias 'mode-highlight 'global-hl-line-mode)
;; change the default file manager
(defalias 'list-directory 'dired)
Bind
;; set global shortcuts
(global-set-key [?\C-k] 'kill-whole-line)
(global-set-key [?\C-$] 'ispell-region)
;; special binding for specific mode (here dired)
(define-key dired-mode-map (kbd "E") 'dired-toggle-read-only))
Hook
;; delete dirty spaces
(add-hook 'before-save-hook 'delete-trailing-whitespace)
"The coolest feature of Emacs is all the available packages." – Doctor Who, the coolest nerd ever
(require 'package)
(setq package-enable-at-startup nil)
(add-to-list 'package-archives
;; `use-package' is not in ELPA, as many more ;-)
'("melpa" . "http://melpa.org/packages/"))
(add-to-list 'package-archives
;; Add org-plus-contrib
'("org" . "http://orgmode.org/elpa/"))
(package-initialize)
M-x package-list-packages
;; boostrap `use-package' by John Wiegley
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
;; load it
(require 'use-package)
Example:
;; change the default file manager
(use-package dired
:defer t
:init
(defalias 'list-directory 'dired)
:config
(define-key dired-mode-map (kbd "E") 'dired-toggle-read-only))
;; example of Julia configuration
(use-package ess
:ensure t
:defer t
;; :init ; example with non-standard loc.
;; (setq inferior-julia-program
;; "/Applications/Julia-0.6.app/Contents/Resources/julia/bin/julia")
:mode (("\\.jl\\'" . ess-julia-mode))
:defines ess-indent-offset ; silent warning
:config
(require 'ess-julia)
(require 'ess-utils)
(setq ess-eval-visibly-p nil)
(setq ess-use-eldoc'script-only))
@simon: do not forget to: sh config-me.sh
@simon: do not forget to turn-on command-log-mode
:-)
# apt-get install aspell
# apt-get install virtualenv ipython
$ pip install jedi epc pylint --user
whitespace-mode
, glasses-mode
, etc.find-grep
, regular expression"Awesome!" – John Kitchin (video)
… start small!
"Don't try to set up the 'final' task managing system from the start. Because you have no idea yet what your system should look like. […] Start by creating and managing a small TODO list and then develop your own system as the needs arises." – Carsten Dominik (creator of org)
… and, in fact, Org can do X
.tex
: C-c C-e C-b l l
(body only)\input{}
(or epxort to buffer C-c C-e C-b l L
and copy/paste)
DEMO!
all: doc.tex table1.tex table2.tex
pdflatex doc.tex
%.tex: %.org
emacs -batch -q $< --eval="(org-latex-export-to-latex nil nil t t)"
clean:
-rm table?.tex
-rm doc.{aux,log}
"Buzzword – What'chu talkin' 'bout, Willis?" – Arnold
First appeared 1958; 60 years ago
"A bad workman blames his tools." – Barack Obama
"Another language is a new life." – Persian proverb
"Learn a language, and you will avoid a war." – Arab proverb
Finally, the truly serious hacker should consider learning Lisp:
Lisp is worth learning for the profound enlightenment experience you will have when you finally get it; that experience will make you a better programmer for the rest of your days, even if you never actually use Lisp itself a lot.
This is the same argument you tend to hear for learning Latin.
Julia uses lisp (parser; try: julia --lisp
) and lot of concepts
(metaprogramming)
See Julia: to Lisp or not to Lisp? (video)
https://learnxinyminutes.com/docs/fr-fr/elisp-fr/
by Bastien Guerry (Org-mode maintainer)
;; work with parenthesis
(show-paren-mode 1) ; highlight matching parens
(electric-pair-mode 1) ; open-close parens
Start REPL
M-x ielm
M-:
Buffer with M-x emacs-lisp-mode
C-x C-e
end of S-expression
;; Declare variable
(setq x 1)
;; Compute (infix)
(+ x 42)
(* x 4.2)
;; List (linked)
(setq ll (list 1 2 3 4))
;; First element (head)
(car ll)
;; Rest (tail)
(cdr ll)
;; Concatenate lists
(append ll (list 11 22 33 44 55) (list "a" "bb" "ccc"))
Function
(defun hello-world (name)
"Simply Hello World function.
Do stuff.
And other stuff.
The argument name provides a name to helloing."
(message "Hello World: %s!" name))
Anonymous function
(lambda (name)
(message "Hello: %s!" name))
Call/Apply a function: (hello-world "Dude")
(defun ask-at-point (&optional i-know)
"Feel free to ask everything."
(interactive "P")
(if i-know (message "Quick Answer.")
(browse-url
(concat "https://www.ddg.gg/?q=emacs+" (thing-at-point 'symbol)))))
Few built-in functions coded in C
C-h f list
or car, cdr, etc.
And lot of Emacs Lisp ones
C-h f ibuffer
or find-file, dired, org, etc.
e.g., eshell
(defun eg/upcase-word ()
"Change from any word to UPPERCASE."
(interactive)
(let ((beg (progn
(backward-word)
(point)))
(end (progn
(forward-word)
(point))))
(upcase-region beg end)))
(global-set-key (kbd "M-u") 'my/upcase-word)
What about Downcase ?
(defun eg/downcase-word ()
"Change from any word to DOWNCASE."
(interactive)
(let ((beg (progn
(backward-word)
(point)))
(end (progn
(forward-word)
(point))))
(downcase-region beg end)))
(defun eg/change-case-word (fun)
"Generic function to change the case of a word.
When the `point' is somewhere in word, first get the `backward-word'
position, second get the `forward-line' position, and last apply FUN
to these both."
(interactive)
(let ((beg (progn
(backward-word)
(point)))
(end (progn
(forward-word)
(point))))
(funcall fun beg end)))
(defun eg/capitalize-word ()
"Remap of `capitalize-word'."
(interactive)
(eg/change-case-word 'capitalize-region))
(defun eg/upcase-word ()
"Remap of `upcase-word'."
(interactive)
(eg/change-case-word 'upcase-region))
(defun eg/downcase-word ()
"Remap of `downcase-word'."
(interactive)
(eg/change-case-word 'downcase-region))
;; add quick bindings to the new nice functions
(global-set-key (kbd "M-c") 'eg/capitalize-word)
(global-set-key (kbd "M-u") 'eg/upcase-word)
(global-set-key (kbd "M-l") 'eg/downcase-word)
Tutorial from VSCode to extend it
https://code.visualstudio.com/docs/extensions/example-word-count
Come on! It is not simpler than X.
(me: javascript is aweful)
M-=
or
M-x count-words-region
(defun eg/count-words-region (start end)
"Count words in the selected region.
Worse than `count-words-region'."
(interactive "r")
(let ((count-words->how-many 0))
(goto-char start)
(while (< (point) end)
(if (forward-word 1)
(setq count-words->how-many (1+ count-words->how-many))))
(message "Region has %d words." count-words->how-many)
count-words->how-many))
M-x eg/count-words-region
Let only consider:
list
and the 4 arithmitic operations on integers and floats\[\cos(x) = \textrm{real}~ \sum_n \frac{ix}{n!}\]
–
Master a tool needs large amount of work
think all the maths you learn before complete non-trivial proofs
Master a tool is not easy; otherwise it is a lie
think nunchaku practise to be as efficient as Bruce Lee
Why computing tools should be different ?
Editor should be freedom, not constraint and pain.