Emacs

Home

Table of Contents

1 Resources

1.1 Installing emacs manual and reference:

cd /usr/share/info/emacs-24
wget https://www.gnu.org/software/emacs/manual/info/emacs.info.gz
wget https://www.gnu.org/software/emacs/manual/info/elisp.info.gz
wget https://www.gnu.org/software/emacs/manual/info/eintr.info.gz

1.2 Reading documentation inside emacs

For the following examples, you can copy&paste the text inside an emacs buffer. Then move the cursor after the closing parentheses, and evaluate the expression with C-x C-e (that is, Ctrl-x followed by Ctrl-e) If you installed the documentation as explained in the previous step, emacs now will open the documentation in a separate buffer. Note that you can also use this trick to bookmark different sections of the manuals.

;;  opens the emacs manual info file
(info "(emacs)")

;;  opens the INFO manual info file
(info "(info)")

;; opens info file emacs, node Abbrevs
(info "(emacs) Abbrevs")

;; opens the emacs manual in the Regular expressions node
(info "(emacs) Regexp s")

;; Different ways to get HELP on emacs
(info "(emacs) Help")
Reload .emacs without restarting.
M-x load-file RET ~/.emacs RET

Search in info manual:
M-x info-apropos   (in emacs)
M-x index-apropos  (standalone reader)

1.3 More resources and sites:

2 Emacs config (draft)

Following are examples of configuration lines that you can add to your .emacs file.

2.1 Basic config

;; Trailing whitespace is unnecessary
(add-hook 'before-save-hook (lambda () (delete-trailing-whitespace)))

;; Make sure all backup files only live in one place
(setq backup-directory-alist '(("." . "~/.emacs.d/backups")))

2.2 More advanced config options (use as needed)

(global-set-key "\M-/" 'hippie-expand)

3 Define function to open URL with Firefox

(defun firefox-tab-url-on-region ()
  "opens URL in region with firefox."
  (interactive)
  (let ((process-connection-type nil))
    (start-process "" nil "/home/seba/firefox/firefox" (buffer-substring (region-beginning) (region-end)) )))
(global-set-key "\C-cw" 'firefox-tab-url-on-region )


;; Opens a URL in Firefox when following the functions are called:
;; browse-url-at-point  C-x m
;; from org-mode  C-c o   'other-frame
(defun firefox-browse-url ( url &optional arg)
  "opens URL with firefox"
  (interactive)
  (let ((process-connection-type nil))
    (start-process "" nil "/home/seba/firefox/firefox" url )))

;;(setq browse-url-browser-function 'w3m-browse-url)
(setq browse-url-browser-function 'firefox-browse-url)

4 Keyboard Shortcuts

http://www.masteringemacs.org/articles/2014/02/28/my-emacs-keybindings/

(global-set-key "\C-o" 'other-window)

enlarge-window                C-x ^
enlarge-window-horizontally   C-x }
shrink-window-horizontally    C-x {

From window.el :

(define-key ctl-x-map "0" 'delete-window)
(define-key ctl-x-map "1" 'delete-other-windows)
(define-key ctl-x-map "2" 'split-window-below)
(define-key ctl-x-map "3" 'split-window-right)
(define-key ctl-x-map "o" 'other-window)
(define-key ctl-x-map "^" 'enlarge-window)
(define-key ctl-x-map "}" 'enlarge-window-horizontally)
(define-key ctl-x-map "{" 'shrink-window-horizontally)
(define-key ctl-x-map "-" 'shrink-window-if-larger-than-buffer)
(define-key ctl-x-map "+" 'balance-windows)
(define-key ctl-x-4-map "0" 'kill-buffer-and-window)

5 Elisp

http://emacslife.com/how-to-read-emacs-lisp.html

C-h v show variable

`M-x set-variable' is limited to user option variables, but you can set any variable with a Lisp expression, using the function `setq'.

 Examining and Setting Variables
---------------------------------
`C-h v VAR <RET>'
     Display the value and documentation of variable VAR
     (`describe-variable').

`M-x set-variable <RET> VAR <RET> VALUE <RET>'
     Change the value of variable VAR to VALUE.

   `M-x set-variable' is limited to user option variables, but you can
set any variable with a Lisp expression, using the function `setq'.
Here is a `setq' expression to set `fill-column':

     (setq fill-column 75)

(setq message-log-max 2000)

message-log-max specifies how many lines Messages can contain

6 Emacs Packages

6.1 w3m

7 Emacs programming tools

7.1 GtkLook

http://www.emacswiki.org/emacs/GtkLook

gtk-look.el finds and displays HTML documentation for Gtk, Glib and Gnome functions and variables, similar to what InfoLook C-h C-i (‘info-lookup-symbol’) does for info format documentation (like the GNU C Library manual).

(define-key global-map [?\C-h ?\C-j] 'gtk-lookup-symbol)

8 Keyboard macros

To record keystrokes, type “Ctrl+x (” then start typing your keystrokes. When done, type “Ctrl+x )”. This records your keystrokes. To run the keystrokes you've recorded, type “Ctrl+x e”.

Here are the command names and their shortcuts:

start-kbd-macro            Ctrl+x (
end-kbd-macro              Ctrl+x )
call-last-kbd-macro        Ctrl+x e

If you want to use your keyboard macro for future use, you can save it. To save the macro, first type “Alt+x name-last-kbd-macro”, then type “Alt+x insert-kbd-macro”, which will insert the lisp code for the keyboard macro at the cursor point. Put the code in your emacs init file (usually at “~/.emacs”). Then, you can execute your keyboard macro like this: “Alt+x yourMacroName” the next time you start emacs.

9 Special key bindings

To find the key code for a particular key, You can use

C-h k describe key

then look at the next examples on how to use the function global-set-key

(global-set-key [(XF86Launch9)] 'ibuffer)
(global-set-key [(XF86Favorites)] 'ibuffer)
(global-set-key [(XF86Forward)] 'ibuffer)
;; C-x C-f
(global-set-key [(XF86Back)] 'find-file)

; other keys to bind: <XF86Favorites>

; control + favorites
; <C-XF86Favorites>

;;undefined
;;alt + special5
;;<M-XF86Launch9>
;;
;;f11, f9, f7, f6, f5,

;; Example Combining F keys with standard keys
(global-set-key (kbd "<f9> i") 'org-clock-in)
(global-set-key (kbd "<f9> j") 'org-clock-jump-to-current-clock)
(global-set-key (kbd "<f9> o") 'org-clock-out)


;;SOME  BINDINGS I LIKE:
;;-----------------------

(global-set-key [(XF86Favorites)] 'bookmark-bmenu-list)
(global-set-key [(XF86Back)] 'find-file)

; open my workspace file  with Special Home key (only some keyboards)
(global-set-key [(XF86HomePage)] (lambda () (interactive) (find-file "~/notas/ws.txt")))

;; rebind menu on f9 key
(global-set-key [f9] 'menu-bar-open )



--------------------------------------------------

10 Other stuff

;;Launch mplayer from inside emacs:
(shell-command "mplayer '/home/sen/Music/meditation.mp4' &" )

DIRED LISTING SWITCHES

C-u s switches <RET>
Refresh the Dired buffer using switches as dired-listing-switches.

C-h v dired-listing-switches

-lagGh --time-style=+%Y
;; change value globally
(setq  dired-listing-switches "-lgGh --time-style=+%Y")
==================================================

M-x desktop-save
M-x desktop-read

==================================================

enlarge-window
  Command: Make the selected window DELTA lines taller.
  Properties: isearch-scroll
enlarge-window-horizontally
  Command: Make selected window DELTA columns wider.

===================================================


(car command-history)
command-history


(shell-command "wget -q -O- http://tromey.com/elpa/package-install.el"  (current-buffer))


==================================================

;; To change the font size interactively per buffer:
;; Up:    C-x C-+, C-x C-=
;; Down:  C-x C--
;; Reset: C-x C-0

==================================================

 Indent all the files in a project using emacs

Use find's exec and reduce the need for multiple evals with a progn wrapper.

lst=`find . -iname \*.c -or -iname \*.h`; for i in $lst; do emacs -nw -q $i --eval "(mark-whole-buffer)" --eval "(indent-region (point-min) (point-max) nil)" --eval "(save-buffer)" --kill; done

find . -iname \*.c -or -iname \*.h -exec emacs -nw -q {} --eval "(progn (mark-whole-buffer) (indent-region (point-min) (point-max) nil) (save-buffer))" --kill \;

11 Emacs 24

M-x package-list-packages

12 TODO - things I'm planning to add soon

  • Creating a TAGS file
  • Navigating using tags
  • Define and using Abbrevs
  • Bookmarks
  • integrating the shell in the workflow
  • M-x visual-line-mode
  • Link to geben tutorial
  • Yasnippet
  • Dired tricks
  • Interactively search and replace

Author: Sebastian Emilio Narvaez

Created: 2019-10-12 Sat 22:16

Emacs 25.2.2 (Org mode 8.2.10)

Validate