Skip to content

Latest commit

 

History

History
431 lines (322 loc) · 11.7 KB

configuration.org

File metadata and controls

431 lines (322 loc) · 11.7 KB

+#+TITLE: Emacs configuration

My personal Emacs config. Some of the stuff pasted from this repository but more of this is mine

Set personal information

(setq user-full-name "Matteo Scarpa"
      user-mail-address "fundor333@fundor333.com"
      calendar-latitude 43.4
      calendar-longitude 12.3
      calendar-location-name "Venice, IT")

Add resources to load-path

(add-to-list 'load-path "~/.emacs.d/resources/")
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes")

Adding the packages you want

Here add all the packages you want install

(setq package-list  '(python all-the-icons dracula-theme jedi helm helm-projectile
	      pdf-tools less-css-mode emojify markdown-mode yaml-mode
            edit-indirect org-bullets auto-complete go-autocomplete
            go-mode web-mode less-css-mode neotree editorconfig powerline
            helm-ag ruby-electric rbenv chruby csv-mode make-mode
            dockerfile-mode ruby-mode php-mode scss-mode achievements pelican-mode))

Package management

(setq package-archives '(("elpa" . "http://tromey.com/elpa/")
                         ("melpa-stable" . "https://stable.melpa.org/packages/")
                         ("melpa" . "http://melpa.org/packages/")
                         ("gnu" . "http://elpa.gnu.org/packages/")
                         ("marmalade" . "http://marmalade-repo.org/packages/")))

; activate all the packages (in particular autoloads)
(package-initialize)

; fetch the list of packages available
(unless package-archive-contents
  (package-refresh-contents))

; install the missing packages
(dolist (package package-list)
  (unless (package-installed-p package)
    (package-install package)))

Adding Hook

(add-hook 'after-init-hook #'global-emojify-mode)
(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))

Adding Startup Stuff

(global-linum-mode t)

NeoTree Setup

(setq neo-theme (if (display-graphic-p) 'icons 'arrow))
(global-set-key [f8] 'neotree-toggle)

Powerline Setup

(powerline-default-theme)

Programming customizations

Editor Config

(require 'editorconfig)
(editorconfig-mode 1)

GoLang

(require 'go-autocomplete)
(require 'auto-complete-config)
(ac-config-default)

Python

Indent 2 spaces.

(setq python-indent 4)

Docker

(add-to-list 'auto-mode-alist '("Dockerfile\\'" . dockerfile-mode))

Ruby

(add-to-list 'auto-mode-alist
             '("\\.\\(?:cap\\|gemspec\\|irbrc\\|gemrc\\|rake\\|rb\\|ru\\|thor\\)\\'" . ruby-mode))
(add-to-list 'auto-mode-alist
             '("\\(?:Brewfile\\|Capfile\\|Gemfile\\(?:\\.[a-zA-Z0-9._-]+\\)?\\|[rR]akefile\\)\\'" . ruby-mode))  

(global-rbenv-mode)
(rbenv-use-global)

Web

(add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.html\\.twig\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))

Sound config

(setq visible-bell t)

Org-mode

Display preferences

Pretty pretty bullets instead of a list of asterisks.

(add-hook 'org-mode-hook
          (lambda ()
            (org-bullets-mode t)))

Arrow instead of ellipsis

(setq org-ellipsis "")

Task and org-capture management

Store my org files in ~/org, maintain an inbox in Dropbox, define the location of an index file (my main todo list), and archive finished tasks in ~/org/archive.org.

(setq org-directory "~/Dropbox/Org")

(defun org-file-path (filename)
  "Return the absolute address of an org file, given its relative name."
  (concat (file-name-as-directory org-directory) filename))

(setq org-inbox-file "~/Dropbox/Org/inbox.org")
(setq org-index-file (org-file-path "index.org"))
(setq org-archive-location
      (concat (org-file-path "archive.org") "::* From %s"))

I use Drafts to create new tasks, format them according to a template, and append them to an “inbox.org” file in my Dropbox. This function lets me import them easily from that inbox file to my index.

(defun hrs/copy-tasks-from-inbox ()
  (when (file-exists-p org-inbox-file)
    (save-excursion
      (find-file org-index-file)
      (goto-char (point-max))
      (insert-file-contents org-inbox-file)
      (delete-file org-inbox-file))))

I store all my todos in ~/org/index.org, so I’d like to derive my agenda from there.

(setq org-agenda-files (list org-index-file))

Hitting C-c C-x C-s will mark a todo as done and move it to an appropriate place in the archive.

(defun hrs/mark-done-and-archive ()
  "Mark the state of an org-mode item as DONE and archive it."
  (interactive)
  (org-todo 'done)
  (org-archive-subtree))

(define-key org-mode-map (kbd "C-c C-x C-s") 'hrs/mark-done-and-archive)

Record the time that a todo was archived.

(setq org-log-done 'time)

Capturing tasks

Define a few common tasks as capture templates. Specifically, I frequently:

  • Record ideas for future blog posts in ~/org/blog-ideas.org,
  • Keep a running grocery list in ~/org/groceries.org, and
  • Maintain a todo list in ~/org/index.org.
(setq org-capture-templates
      '(("b" "Blog idea"
         entry
         (file (org-file-path "blog-ideas.org"))
         "* TODO %?\n")

        ("g" "Groceries"
         checkitem
         (file (org-file-path "groceries.org")))

        ("l" "Today I Learned..."
         entry
         (file+datetree (org-file-path "til.org"))
         "* %?\n")

        ("r" "Reading"
         checkitem
         (file (org-file-path "to-read.org")))

        ("t" "Todo"
         entry
         (file+headline org-index-file "Inbox")
         "* TODO %?\n")))

When I’m starting an org capture template I’d like to begin in insert mode. I’m opening it up in order to start typing something, so this skips a step.

(add-hook 'org-capture-mode-hook 'evil-insert-state)

Keybindings

Hit C-c i to quickly open up my todo list.

(defun open-index-file ()
  "Open the master org TODO list."
  (interactive)
  (hrs/copy-tasks-from-inbox)
  (find-file org-index-file)
  (flycheck-mode -1)
  (end-of-buffer))

(global-set-key (kbd "C-c i") 'open-index-file)

Exporting

Allow export to markdown and beamer (for presentations).

(require 'ox-md)
(require 'ox-beamer)

Translate regular ol’ straight quotes to typographically-correct curly quotes when exporting.

(setq org-export-with-smart-quotes t)

Exporting to HTML

Don’t include a footer with my contact and publishing information at the bottom of every exported HTML document.

(setq org-html-postamble nil)

Exporting to PDF

I want to produce PDFs with syntax highlighting in the code. The best way to do that seems to be with the minted package, but that package shells out to pygments to do the actual work. pdflatex usually disallows shell commands; this enables that.

(setq org-latex-pdf-process
      '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
        "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
        "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))

Include the minted package in all of my LaTeX exports.

(add-to-list 'org-latex-packages-alist '("" "minted"))
(setq org-latex-listings 'minted)

TeX configuration

I rarely write LaTeX directly any more, but I often export through it with org-mode, so I’m keeping them together.

Automatically parse the file after loading it.

(setq TeX-parse-self t)

Always use pdflatex when compiling LaTeX documents. I don’t really have any use for DVIs.

(setq TeX-PDF-mode t)

Enable a minor mode for dealing with math (it adds a few useful keybindings), and always treat the current file as the “main” file. That’s intentional, since I’m usually actually in an org document.

(add-hook 'LaTeX-mode-hook
          (lambda ()
            (LaTeX-math-mode)
            (setq TeX-master t)))

Daily checklist

There are certain things I want to do every day. I store those in a checklist. That’s an ERB template wrapping an Org document, since different things happen on different days.

Hitting C-c t either opens today’s existing checklist (if it exists), or renders today’s new checklist, copies it into an Org file in /tmp, and opens it.

(setq hrs/checklist-template "~/documents/daily-checklist.org.erb")

(defun hrs/today-checklist-filename ()
  "The filename of today's checklist."
  (concat "/tmp/daily-checklist-" (format-time-string "%Y-%m-%d") ".org"))

(defun hrs/today ()
  "Take a look at today's checklist."
  (interactive)
  (let ((filename (hrs/today-checklist-filename)))
    (if (file-exists-p filename)
        (find-file filename)
      (progn
        (shell-command (concat "erb " hrs/checklist-template " > " filename))
        (find-file filename)))))

(global-set-key (kbd "C-c t") 'hrs/today)

Using GNOME startup and session manager

 ;;; save & shutdown when we get an "end of session" signal on dbus
 (require 'dbus)

 (defun my-register-signals (client-path)
 "Register for the 'QueryEndSession' and 'EndSession' signals from
 Gnome SessionManager.

 When we receive 'QueryEndSession', we just respond with
 'EndSessionResponse(true, \"\")'.  When we receive 'EndSession', we
 append this EndSessionResponse to kill-emacs-hook, and then call
 kill-emacs.  This way, we can shut down the Emacs daemon cleanly
 before we send our 'ok' to the SessionManager."
 (setq my-gnome-client-path client-path)
 (let ( (end-session-response (lambda (&optional arg)
 (dbus-call-method-asynchronously
 :session "org.gnome.SessionManager" my-gnome-client-path
 "org.gnome.SessionManager.ClientPrivate" "EndSessionResponse" nil
 t "") ) ) )
 (dbus-register-signal
 :session "org.gnome.SessionManager" my-gnome-client-path
 "org.gnome.SessionManager.ClientPrivate" "QueryEndSession"
 end-session-response )
 (dbus-register-signal
 :session "org.gnome.SessionManager" my-gnome-client-path
 "org.gnome.SessionManager.ClientPrivate" "EndSession"
 `(lambda (arg)
 (add-hook 'kill-emacs-hook ,end-session-response t)
 (kill-emacs) ) ) ) )

 ;; DESKTOP_AUTOSTART_ID is set by the Gnome desktop manager when emacs
 ;; is autostarted.  We can use it to register as a client with gnome
 ;; SessionManager.
 (dbus-call-method-asynchronously
 :session "org.gnome.SessionManager"
 "/org/gnome/SessionManager"
 "org.gnome.SessionManager" "RegisterClient" 'my-register-signals
"Emacs server" (getenv "DESKTOP_AUTOSTART_ID"))

Pelican config

(require 'pelican-mode)
(pelican-global-mode)