Skip to content

Latest commit

 

History

History
212 lines (158 loc) · 4.24 KB

day-3.org

File metadata and controls

212 lines (158 loc) · 4.24 KB

Emacs training day 3

Emacs general utilities

  • C-o : open-line
  • macro
  • M-| : shell-command-on-region
  • (region-beginning)
  • (region-end)
  • macros
  • funcall
  • apply
  • (completing-read "Prompt: " '("alice" "bob" "eva"))
  • (read-from-minibuffer "Prompt: ")
  • (read-regexp "Your regexp: ")
  • regexp-quote
  • (regexp-opt '("abc" "bcd"))
  • read-char
  • bolp (beginning of line?)
  • eolp (end of line?)

Using timers

Variables:

  • timer-list
  • timer-idle-list

Cloning and compiling emacs

~$ git clone git://git.savannah.gnu.org/emacs.git

org-mode table and spreadsheets

  • org-table-create
  • org-table-import (csv, tsv)
  • TAB and S-TAB
  • S-RET
  • C-c .
  • S-M-left : delete the column
  • S-M-right : insert a new column
  • C-c { : activate the table formulas debugger
  • S-M-up : delete the line
  • S-M-down : insert a new line
  • info:org#The spreadsheet
  • C-c = : column formula
  • C-u C-c = : field formula
  • references
  • formulas debugger
  • remote ref

Examples

See Table 1 and Table 2.

Shell and elisp links

shell:du -h

elisp:(message “yo”)

Check org-confirm-elisp-link-function and org-confirm-shell-link-function.

Org-mode babel

See Babel.

Elisp macros

(setq x 3)

(setq x 3 y 4)

(inc x)
;; => 4

(macroexpand '(inc x))
;; => (setq x (1+ x))

;; (inc x) <=> (setq x (1+ x))
(defmacro inc (var)
   (list 'setq var (list '1+ var)))

;; (inc2 x) <=> (inc x)
(defmacro inc2 (var)
   `(setq ,var (1+ ,var)))

(inc2 x)

(macroexpand '(inc2 x))

(defmacro let-a-3 (&rest body)
   `(let ((msg "hello"))
      ,@body))

(let-a-3 ;; msg is always defined
 (message "blabla")
 (sit-for 2)
 (message msg))
;; => 5

See org-preserve-lc for a use of ,@body.

Using the mode-line

  • global-mode-string (a list!)
  • force-mode-line-update

Code snippets init files

  • dblock in org-mode
  • (setq org-support-shift-select t)
  • (setq use-dialog-box nil)
  • (define-key global-map "\M-Q" 'unfill-paragraph)
  • obarray
  • intern
  • benchmark-run
  • defface
  • shell-command
  • org-caldav-sync
  • (setq org-export-with-broken-links t)
#+BEGIN: clocktable :maxlevel 2 :scope file
#+CAPTION: Clock summary at [2016-07-22 ven. 16:00]
| Headline   | Time |
|------------+------|
| *Total time* | *0:00* |
#+END:

ert, elp, profile-start, benchmark-run

  • elp-intrument-function
  • elp-results
  • profile-start, profile-report
  • benchmark-run
  • ert
  • assert
  • checkdoc

Use org-cycle in emacs-lisp-mode

(add-hook 'emacs-lisp-mode-hook 'turn-on-orgstruct)

(global-set-key
 (kbd "C-M-]") (lambda () (interactive) (org-cycle t)))

(global-set-key
 (kbd "M-]") (lambda () (interactive)
	       (ignore-errors (end-of-defun) (beginning-of-defun)) (org-cycle)))

Calling processes synchronously

(call-process-shell-command "echo \"/^abc$/\" | pcretest")

(call-process "pcretest.sh" nil t nil "^abc")

;; See also
;; shell-command
;; M-| : shell-command-on-region

Continue sns-mode (auto-fill, indent-line, etc.)

  • Write sns-return to do the right thing
    • looking-at
    • looking-back
  • Fix font-lock-defaults (don’t use font-lock-add-keywords, See manual)
  • auto-fill behavior (See fill-paragraph-function)
  • indent-line behavior (See indent-line-function)
  • defining options and faces
    • defgroup
    • defcustom
    • defface
  • adding an advice with ad-advice

Continue sns-mode (hooks)

  • add-hook : e.g. (add-hook 'lisp-interaction-mode-hook 'auto-fill-mode)
  • remove-hook
  • run-hook
  • delay-mode-hooks
  • before-save-hook
  • before-init-hook
;; Examples: hooks in Org-mode
(defcustom org-mode-hook nil
  "Mode hook for Org-mode, run after the mode was turned on."
  :group 'org
  :type 'hook)

;;;###autoload
(defun org-clock-persistence-insinuate ()
  "Set up hooks for clock persistence."
  (require 'org-clock)
  (add-hook 'org-mode-hook 'org-clock-load)
  (add-hook 'kill-emacs-hook 'org-clock-save))

Magit demo