Skip to content

Latest commit

 

History

History
310 lines (246 loc) · 11.7 KB

emacs-client.org

File metadata and controls

310 lines (246 loc) · 11.7 KB

Client Configuration for Emacs

The settings in this file are only included on a Macintosh, Linux, or other systems with a graphical front-end.

Needed Packages

(packages-install '( color-theme
                     color-theme-sanityinc-tomorrow
                     highlight-tail          ;; Used only sporadically
                   ))

Key Bindings

Gotta get rid of the bloody C-x C-c, for it is too close to the tangling key binding of C-c C-v … besides, I never quit Emacs.

(defun dont-kill-emacs ()
  "This just prints a message with the correct way to stop Emacs."
  (interactive)
  (message "If you really want to quit emacs, call `save-buffers-kill-emacs' directly."))

(global-set-key (kbd "C-x C-c") 'dont-kill-emacs)

I would like Command-W to close a frame, but only if it only has a single window in it. I found this code on this site.

(defun delete-single-window (&optional window)
  "Remove WINDOW from the display.  Default is `selected-window'.
If WINDOW is the only one in its frame, then `delete-frame' too."
  (interactive)
  (save-current-buffer
    (setq window (or window (selected-window)))
    (select-window window)
    (kill-buffer)
    (if (one-window-p t)
        (delete-frame)
        (delete-window (selected-window)))))

Font Settings

I love syntax highlighting.

(global-font-lock-mode 1)

Am I really a monospace font slut? I think so. I keep changing my font based on the monospace du jour… right now, I am liking M+ since it is thinner and has more white space between lines.

However, I find Source Code Pro quite attractive, as well as Anonymous Pro.

;; (setq my/font-family "M+ 1mn")
(setq my/font-family "Source Code Pro")
;; (setq my/font-family "Anonymous Pro")

With the font name situated, I just need to use that to set the three magic frame settings:

(set-frame-font my/font-family)
(set-face-attribute 'default nil :font my/font-family :height 120)
(set-face-font 'default my/font-family)

Note: I find that the height should be 160 for M+, but 140 for most other fonts.

Color Theme

Use the color theme project by following these instructions. We now can do M-x color-theme-<TAB> RET

(require 'color-theme)

The color themes work quite well, except they don’t know about the org-mode source code blocks, so we need to set up a couple functions that we can use to set them.

(defun org-src-color-blocks-light ()
  "Colors the block headers and footers to make them stand out more for lighter themes"
  (interactive)
  (custom-set-faces
   '(org-block-begin-line
    ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))
   '(org-block-background
     ((t (:background "#FFFFEA"))))
   '(org-block-end-line
     ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))))

   '(mode-line-buffer-id ((t (:foreground "#005000" :bold t))))
   '(which-func ((t (:foreground "#008000")))))

   ;; Looks like the minibuffer issues are only for v23
   ; (set-face-foreground 'minibuffer "black")
   ; (set-face-foreground 'minibuffer-prompt "red")
)

(defun org-src-color-blocks-dark ()
  "Colors the block headers and footers to make them stand out more for dark themes"
  (interactive)
  (custom-set-faces
   '(org-block-begin-line
     ((t (:foreground "#008ED1" :background "#002E41"))))
   '(org-block-background
     ((t (:background "#111111"))))
   '(org-block-end-line
     ((t (:foreground "#008ED1" :background "#002E41"))))

   '(mode-line-buffer-id ((t (:foreground "black" :bold t))))
   '(which-func ((t (:foreground "green")))))

   ;; Looks like the minibuffer issues are only for v23
   ;; (set-face-foreground 'minibuffer "white")
   ;; (set-face-foreground 'minibuffer-prompt "white")
)

No matter, the theme, I like some of the ideas in the EMagicians Starter Kit, particularly in how the headers are larger, not different colors. Also, the headers are based on Adobe’s open source font, Source Sans Pro (as I think that will match the Source Code Pro).

(deftheme ha/org-theme "Sub-theme to beautify org mode")

Since I’m using the Powerline project, switching my Emacs color theme, requires me to call powerline-reset in order to get the colors to apply to the mode line.

We put all of these requirements in a single function call:

(defun ha/change-theme (theme org-block-style)
  "Changes the color scheme and reset the mode line."
  (funcall theme)
  (powerline-reset)
  (funcall org-block-style)

  (let* ((sans-font (cond ((x-list-fonts "Source Sans Pro") '(:font "Source Sans Pro"))
                          ((x-list-fonts "Lucida Grande")   '(:font "Lucida Grande"))
                          ((x-list-fonts "Verdana")         '(:font "Verdana"))
                          ((x-family-fonts "Sans Serif")    '(:family "Sans Serif"))
                          (nil (warn "Cannot find a Sans Serif Font.  Install Source Sans Pro."))))
         (base-font-color  (face-foreground 'default nil 'default))
         (background-color (face-background 'default nil 'default))
         (primary-color    (face-foreground 'mode-line nil))
         (secondary-color  (face-background 'secondary-selection nil 'region))
         (headline        `(:inherit default :weight bold :foreground ,base-font-color)))
    (custom-theme-set-faces 'ha/org-theme
                            `(org-agenda-structure ((t (:inherit default ,@sans-font :height 2.0 :underline nil))))
                            `(org-level-8 ((t (,@headline ,@sans-font))))
                            `(org-level-7 ((t (,@headline ,@sans-font))))
                            `(org-level-6 ((t (,@headline ,@sans-font))))
                            `(org-level-5 ((t (,@headline ,@sans-font))))
                            `(org-level-4 ((t (,@headline ,@sans-font :height 1.1))))
                            `(org-level-3 ((t (,@headline ,@sans-font :height 1.25))))
                            `(org-level-2 ((t (,@headline ,@sans-font :height 1.5))))
                            `(org-level-1 ((t (,@headline ,@sans-font :height 1.75))))
                            `(org-document-title ((t (,@headline ,@sans-font :height 1.5 :underline nil)))))))

And the default startup goes to…night…unless I’m at work, and then we’ll take the bright shiny theme.

(if (equal "howard.abrams" user-login-name)
  (ha/change-theme 'color-theme-sanityinc-tomorrow-day
                   'org-src-color-blocks-light)
  (ha/change-theme 'color-theme-sanityinc-tomorrow-night
                   'org-src-color-blocks-dark))

My main reason for wanting to use the color theme project is to switch between black on white during the day, and white on black at night. Because I have to pass function references to my define-sequence macro, I use the list function call instead of quoting the list:

(define-sequence 'personal-theme-map "<f9> d" 'ha/change-theme
  (list (list "d" 'color-theme-sanityinc-tomorrow-day      'org-src-color-blocks-light)  ; White on Black
        (list "l" 'color-theme-sanityinc-tomorrow-eighties 'org-src-color-blocks-dark)   ; Lt. Gray on Gray
        (list "m" 'color-theme-sanityinc-tomorrow-bright   'org-src-color-blocks-dark)   ; Bright on Black
        (list "n" 'color-theme-sanityinc-tomorrow-night    'org-src-color-blocks-dark))) ; White on Gray

Undo and Redo

According to this article, I get better functionality than the redo+ plugin (which I can’t seem to get working well).

(require 'undo-tree)
(global-undo-tree-mode 1)
(defalias 'redo 'undo-tree-redo)

(global-set-key (kbd "C-z") 'undo) ; Zap to character isn't helpful
(global-set-key (kbd "C-S-z") 'redo)

Frame and Window Size

I often want to put the window fullscreen:

(defun frame-fullscreen ()
  "Set the frame window to cover the full screen."
  (interactive)
  (set-frame-parameter nil 'fullscreen 'fullboth))

When I am using my large monitors with a full-screen Emacs session with two or three side-by-side windows, I want set them to a fixed width:

(defun set-window-width (&optional width)
  "Sets the size of the current window to a specific width.
If no width is specified, it defaults to ~ 80 characters."
  (interactive "p")
  (save-excursion
    (if (not width)
        (setq width 78))
    (if (> (window-width) width)
        (shrink-window-horizontally (- (window-width) width))
      (enlarge-window-horizontally (- width (window-width))))))

The bell is pretty obnoxious when it dings during scrolling.

(setq ring-bell-function 'ignore)

Twitter

I know, I know, reading my twitter feed in Emacs is pretty geeking awesome. And I can filter out tweets that match a pattern that annoys me:

(setq twittering-tweet-filters '("kickstart" "#burritowatch"))

(defun twittering-filter-tweets ()
  (setq non-matching-statuses '())
  (dolist (status twittering-new-tweets-statuses)
    (setq matched-tweets 0)
    (dolist (pat twittering-tweet-filters)
      (if (string-match pat (cdr (assoc 'text status)))
          (setq matched-tweets (+ 1 matched-tweets))))
    (if (= 0 matched-tweets)
        (setq non-matching-statuses (append non-matching-statuses `(,status)))))
  (setq new-statuses non-matching-statuses))

(add-hook 'twittering-new-tweets-hook 'twittering-filter-tweets)

Need to enable spell-checking for the Twitter mode.

(add-hook 'twittering-edit-mode-hook (lambda () (ispell-minor-mode) (flyspell-mode)))

Technical Artifacts

Load up the particular operating system variation.

(if (eq system-type 'darwin)
    (require 'init-mac)
  (require 'init-linux))

Notice “Windows” is not listed. That is by design.

Make sure that we can simply require this library.

(provide 'init-client)

Before you can build this on a new system, make sure that you put the cursor over any of these properties, and hit: C-c C-c