Skip to content

Self executing presentation on Emacs initialization with packages

Notifications You must be signed in to change notification settings

dgtized/brave-new-emacs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Brave New Emacs

Preamble

Instructions

To follow along locally using Emacs 25;

git clone https://github.com/dgtized/brave-new-emacs.git
cd brave-new-emacs
emacs -q README.org &

Incantations to Setup Presentation

  • Ensure we are not using the default .emacs.d.
  • Unnecessary for an actual configuration
  • Type C-c C-c in BEGIN_SRC block below to install
  • Press F7 to start/resume presentation mode (q to quit)
(setq user-emacs-directory (concat (getenv "PWD") "/"))
(setq package-user-dir (locate-user-emacs-file "elpa"))
(add-to-list 'load-path user-emacs-directory t)
;; From https://raw.github.com/eschulte/epresent/master/epresent.el
(require 'epresent)
(global-set-key (kbd "<f7>") 'epresent-run)
;; Disable prompting to evaluate babel blocks
(setq org-confirm-babel-evaluate nil)

Alternate Presentation Mode

;; From https://raw.github.com/takaxp/org-tree-slide/master/org-tree-slide.el
(require 'org-tree-slide)
(global-set-key (kbd "<f8>") 'org-tree-slide-mode)
(global-set-key (kbd "S-<f8>") 'org-tree-slide-skip-done-toggle)

Init, Modes and Keybindings

Emacs

  • Binary is an emacs lisp interpreter
  • Majority of functionality is written in elisp
  • No difference between user code and distribution

Initialization

Startup loads init files prior to giving control to user

  1. loadup.el system libraries
  2. Site or distribution
  3. User (~/.emacs, ~/.emacs.el or ~/.emacs.d/init.el)

Major Mode

  • Defines how a user interacts with the editor syntax tables, derived modes, keybindings, menus
  • Only one active at a time

Examples:

  • org-mode
  • emacs-lisp-mode
  • eshell-mode
  • minibuffer

Minor Modes

As many as you want

Examples:

  • column-number-mode
  • visual-line-mode
  • flyspell-mode
  • transient-mark-mode
  • show-paren-mode

Keybindings

Global
The top level binding
Prefix
Use prefix and dispatch to new map
Minimap
Temporary mode with different bindings

Try C-x C-h or C-x a C-h for binding help for prefix

Keymaps are inherited or unique

Keybinding Examples

KeybindingDescription
C-x C-eEval previous expression
C-M-xEval defun
C-u C-M-xDebug defun at point
TABOrg and Magit Toggle
C-h mMode specific help
C-h kKey specific help
C-h bList all bindings
C-h fFunction specific help
C-c C-cOrg-mode DWIM at point

Hooks and defadvice

  • Hooks are callbacks to run a list of functions add-hook, remove-hook, run-hooks Examples: org-mode-hook, prog-mode-hook
  • defadvice for aspect oriented programming around, before, after on any function
  • For extending existing functionality

Bare Necessities

  • Stop asking yes or no, y or n suffice
  • Find library source for any installed library
  • C-x C-j to jump to dired for current file
(defalias 'yes-or-no-p 'y-or-n-p)
(define-key help-map (kbd "C-l") 'find-library)
(require 'dired-x)

Libraries and Packages

Library

A file or files containing elisp

rot13
decrypt rot13 library/mode
ido
minor mode extending minibuffer completion
simple
the basic editor commands
  • isearch, linum, byte-compiler, interpeter, edebug, menu

Load Path

Where to look for libraries and when to load

Load
Always executes
(load "/path/to/library")
    
Provide
Names a files code ‘foo
(provide 'foo)
    
Require
Conditionally load ‘foo from load-path
(require 'foo)
    
Autoload
Requires ‘foo if ‘foo-func is used
(autoload 'foo-func 'foo)
    

Package.el

  • Automatically downloads emacs packages from an archive
  • Updates installed packages
  • Extends load-path and generates package autoloads
  • Builtin since Emacs 24

Package Archives

Melpa
Milkypostman’s Emacs Lisp Package Archive latest and bleeding edge
Marmalade
Spreadable Elisp versioned and recent
ELPA
Emacs Lisp Package Archive Hosted at GNU Savannah, FSF-GPL only
(require 'package)
(add-to-list
 'package-archives
 '("melpa" . "https://melpa.org/packages/"))
(package-initialize)

Manually Install Packages

M-x package-list-packages and install better-defaults

imarks package for Install
dmarks package for Deletion
xeXecutes pending
Umark Upgrades
uUnmark package
hHelp

Automatically Install Missing Packages

Just copy your init.el file and start emacs

(defun ensure-packages (package-list)
  "Ensures packages in list are installed locally"
  (unless (file-exists-p package-user-dir)
    (package-refresh-contents))
  (dolist (package package-list)
    (unless (package-installed-p package)
      (package-install package))))

(ensure-packages '(better-defaults))

Package Development

Keywords in package header

Package-Requires
package dependency list
Version
for specific versions

github-browse-settings

Example Package

M-x package-install-from-file not-in-load-path/github-browse-settings.el

Package is now installed in package-user-dir

For development try package-install-from-buffer

To run this automatically;

(package-install-file "not-in-load-path/github-browse-settings.el")
(require 'github-browse-settings)

Useful Extensions

Smex

Smart M-x, or Ido for M-x

(ensure-packages '(smex))
(global-set-key (kbd "C-x C-m") 'smex)
(global-set-key (kbd "C-c C-m") 'smex-major-mode-commands)
(setq avy-background t
      avy-style 'at-full)

Avy / Ace Jump Mode

Faster than a speeding mouse!

(ensure-packages '(avy))
(global-set-key (kbd "C-;") 'avy-goto-word-or-subword-1)
(global-set-key (kbd "C-M-;") 'avy-pop-mark)

Magit

magit is friends with git

(ensure-packages '(magit))
(global-set-key (kbd "C-x g") 'magit-status)
magit-blame-mode
Inline blame mode
magit-file-log
Show git log for file

Projectile

projectile uses version control to define a project

Try C-c p C-h to see all it provides

(ensure-packages '(projectile))
(projectile-global-mode)

Elisp Navigation

Quickly navigate to function at point in elisp with xref

M-.jump to function
M-,return to last point

Eldoc is also builtin and shows function arguments in the minibuffer

(dolist (hook '(emacs-lisp-mode-hook ielm-mode-hook))
  (add-hook hook 'turn-on-eldoc-mode))

Themes!

Zenburn is a nice dark theme

(ensure-packages '(zenburn-theme))
(load-theme 'zenburn t)

Org Links

Org can create links like so:

[[href][name]]
(global-set-key (kbd "C-c l") 'org-store-link)

C-c C-l to link in org-mode, C-c C-o to visit

Demo

Type C-c C-v t to generate init.el from this file.

At the terminal:

emacs -q -l init.el &

Use C-c ’ to edit BEGIN_SRC blocks in their own major mode

Questions or Comments?

About

Self executing presentation on Emacs initialization with packages

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published