Skip to content

Instantly share code, notes, and snippets.

@markcameron
Last active December 31, 2015 12:39
Show Gist options
  • Save markcameron/7987932 to your computer and use it in GitHub Desktop.
Save markcameron/7987932 to your computer and use it in GitHub Desktop.
Emacs init file for 24.2 on Windows 8.1
(setq emacs-related-path "C:/Program Files/emacs-24.2/emacs-related/")
(add-to-list 'load-path emacs-related-path)
;; No Blinking Cursor
(blink-cursor-mode 0)
;; No Toolbar
(tool-bar-mode 0)
;; No Menu Bar
(menu-bar-mode 0)
;; No Scrollbars
(set-scroll-bar-mode nil)
(defadvice new-frame (after scroll-bar-mode activate)
(set-scroll-bar-mode nil))
;; No Auto Save
(auto-save-mode 0)
;; Put all ~ files in this folder:
(setq backup-directory-alist '((".*" . "~/emacstrash")))
;; Make window transparent
(set-frame-parameter (selected-frame) 'alpha '(90 90)) ;(<active> [<inactive>])
(add-to-list 'default-frame-alist '(alpha 90 90))
;; Remove silly <2> at the end of duplicate files
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)
;; Remember position in document across opens
(require 'saveplace)
(setq-default save-place t)
(setq save-place-file (concat user-emacs-directory "places"))
;; Scroll window under mouse
(setq mouse-wheel-follow-mouse 't)
;; Show trailing whitespace
(setq-default show-trailing-whitespace t)
;; Removing trailing whitespace on save
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;; IDO Mode - Don't like it uncomment for those who like
;(ido-mode t)
; (setq ido-enable-flex-matching t)
;; Set UTF-8 as file encoding - Also unix CR/LF for new files
;; Just about every variable I could find to force it!
(setq default-buffer-file-coding-system 'utf-8-unix)
(set-language-environment 'utf-8)
(setq locale-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(unless (eq system-type 'windows-nt)
(set-selection-coding-system 'utf-8))
(prefer-coding-system 'utf-8-unix)
;; YASnippet
(add-to-list 'load-path
(concat emacs-related-path "yasnippet"))
(require 'yasnippet) ;; not yasnippet-bundle
(yas/initialize)
(yas/load-directory (concat emacs-related-path "yasnippet/snippets"))
;; Default Folders [HOME]
(setq homepath "C:/wamp/www/")
(setq default-directory "C:/wamp/www/")
;; Treat clipboard input as UTF-8 string first; compound text next, etc.
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))
; Enable Doxygen syntax highlighting for C and C++
; Mainly for C-x C-c auto comment blocks below
(require 'doxymacs)
;; Allow function comments with C-x c
(global-set-key "\C-x\c" 'doxymacs-insert-function-comment)
;; Replace 'yes' by 'y'
(fset 'yes-or-no-p 'y-or-n-p)
;; Ask on close emacs
(defun ask-before-closing ()
"Ask whether or not to close, and then close if y was pressed"
(interactive)
(if (y-or-n-p (format "Are you sure you want to exit Emacs? "))
(if (< emacs-major-version 22)
(save-buffers-kill-terminal)
(save-buffers-kill-emacs))
(message "Canceled exit")))
(when window-system
(global-set-key (kbd "C-x C-c") 'ask-before-closing))
;; Default Encoding
;(set-terminal-coding-system 'utf-8)
;; pending delete
(pending-delete-mode)
;; Set Colors
(set-background-color "black")
(set-border-color "white")
(set-border-color "green")
(set-cursor-color "white")
(set-foreground-color "white")
(set-mouse-color "red")
(setq default-frame-alist
(append default-frame-alist
'((foreground-color . "white")
(background-color . "Black")
(set-border-color "white")
(cursor-color . "white")
)))
;; Set font face and size
(set-face-attribute 'default nil :font "Monaco-10")
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(cperl-array-face ((((class color) (background dark)) (:foreground "LimeGreen" :weight bold))) t)
'(cperl-hash-face ((((class color) (background dark)) (:foreground "LimeGreen" :slant italic :weight bold))) t)
'(font-lock-comment-face ((t (:bold nil :foreground "DeepPink"))))
'(font-lock-string-face ((t (:foreground "plum")))))
;; Switch between visible buffers using Alt+Right and Alt+Left
(global-set-key [(meta right)] 'other-window)
(global-set-key [(meta left)] '(lambda()
(interactive)
(other-window -1)
))
; C-x k Kills the buffer without confirmation
(global-set-key (read-kbd-macro "C-x k") (quote kill-this-buffer))
;; Auto-Complete with Ctrl+Tab
(abbrev-mode t)
(global-set-key (quote [C-tab]) (quote dabbrev-expand))
;; C-a C-k removes whole line, not just text [includes carriage return]
(setq kill-whole-line t)
;; Remove splash screen
(setq inhibit-splash-screen t)
; Show column number
(column-number-mode 1)
; Highlight matching {} ()
(show-paren-mode 1)
(setq blink-matching-paren-on-screen t)
; Add a final newline to files that don't have one without asking.
(setq require-final-newline t)
;; Notepad++ comment/uncomment system
(defun toggle-comment()
"Toggle the // style comments at the beginning of a line"
(interactive)
; Save cursor position for later.
(setq cursor (point))
; Setup comment string
(setq comment-str "//")
(setq comment-size (length comment-str))
(move-beginning-of-line nil)
; Get current line from buffer and check if it is commented or not
; and apply or remove comment accordingly
(setq line-of-code (buffer-substring (line-beginning-position) (line-end-position)))
(if (not (equal (substring line-of-code 0 comment-size) comment-str))
(progn
(setq line-of-code (concat comment-str line-of-code))
(setq cursor (+ cursor comment-size))
)
(if (string= (substring line-of-code 0 comment-size) comment-str)
(progn
(setq line-of-code (substring line-of-code comment-size nil))
(setq cursor (- cursor comment-size))
)
)
)
; Overwrite old line with the newly commented one.
(kill-line)
(insert line-of-code)
(newline)
(goto-char cursor)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; MODES ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PHP
(add-to-list 'load-path (concat emacs-related-path "php-mode"))
(require 'php-mode)
(defconst my-php-style
'((c-offsets-alist . (
(arglist-close . c-lineup-close-paren) ; correct arglist closing parenthesis
)))
"My PHP Programming style"
)
(c-add-style "my-php-style" my-php-style)
; Drupal
(defun drupal-mode ()
"Drupal php-mode."
(interactive)
(php-mode)
(message "Drupal mode activated.")
(set 'tab-width 2)
(set 'c-basic-offset 2)
(set 'indent-tabs-mode nil)
(c-set-offset 'case-label '+)
; for FAPI arrays and DBTNG
(c-set-offset 'arglist-intro '+)
; for DBTNG fields and values
(c-set-offset 'arglist-cont-nonempty 'c-lineup-math)
; More Drupal-specific customizations here
)
(defun unident-closure ()
(let ((syntax (mapcar 'car c-syntactic-context)))
(if (and (member 'arglist-cont-nonempty syntax)
(or
(member 'statement-block-intro syntax)
(member 'brace-list-intro syntax)
(member 'brace-list-close syntax)
(member 'block-close syntax)
(member 'topmost-intro-cont)))
(save-excursion
(beginning-of-line)
(delete-char (* (count 'arglist-cont-nonempty syntax)
c-basic-offset))))))
;; PHP Mode hook
(add-hook 'php-mode-hook 'my-php-mode-hook)
(defun my-php-mode-hook ()
"My PHP mode configuration."
(c-set-style "my-php-style")
;; Tabs are 2 spaces
(setq indent-tabs-mode nil
tab-width 2
c-basic-offset 2)
;; Drupal
(add-to-list 'auto-mode-alist '("\\.\\(module\\|test\\|install\\|theme\\)$" . drupal-mode))
(add-to-list 'auto-mode-alist '("/drupal.*\\.\\(php\\|inc\\)$" . drupal-mode))
(add-to-list 'auto-mode-alist '("\\.info" . conf-windows-mode))
(add-hook 'c-special-indent-hook 'unident-closure)
)
;; CSS
(setq cssm-indent-level 4)
(setq cssm-newline-before-closing-bracket t)
(setq cssm-indent-function #'cssm-c-style-indenter)
(setq cssm-mirror-mode nil)
;; Web Mode
(require 'web-mode)
(add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
(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 '("\\.blade\\.php\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.jsp\\'" . web-mode))
(setq web-mode-engines-alist
'(("php" . "\\.phtml\\'")
("blade" . "\\.blade\\."))
)
;; JavaScript
(setq-default indent-tabs-mode nil)
(setq js-indent-level 2)
;; Package
(require 'package)
(add-to-list 'package-archives
'("marmalade" .
"http://marmalade-repo.org/packages/"))
(package-initialize)
;; MACROS
(fset 'macro-out
"\C-a$out .= '\C-e';\C-n\C-a")
(fset 'macro-echo
"\C-aecho '\C-e';\C-n\C-a")
(fset 'dpr
[?d ?p ?r ?\( ?\) ?\; left left ?$ C-tab])
(fset 'devnetz-tramp
"\C-x\C-f\C-a\C-k/plink:mark@devnetz.ch:/home/mark/www/")
(fset 'blue-tramp
"\C-x\C-f\C-a\C-k/plink:www-dev@blue:~/")
(fset 'wefextranet-tramp
"\C-x\C-f\C-a\C-k/plink:mcameron@lxuser01:/home/WEFORUM/mcameron/dev/extranet/Extranet/website")
(defun indent-buffer ()
(interactive)
(untabify (point-min) (point-max))
(save-excursion (indent-region (point-min) (point-max) nil))
)
; Custom KBD SHortcuts
(global-set-key [f5] 'indent-buffer)
(global-set-key [f10] 'blue-tramp)
(global-set-key [f11] 'devnetz-tramp)
(global-set-key [f12] 'wefextranet-tramp)
(global-set-key "\C-x\M-o" 'macro-out)
(global-set-key "\C-x\M-e" 'macro-echo)
(global-set-key "\C-x\p" 'dpr)
(global-set-key "\M-g" 'goto-line)
(global-set-key "\C-q" 'toggle-comment)
(global-set-key [(home)] 'beginning-of-line)
(global-set-key [(C-home)] 'beginning-of-buffer)
(global-set-key [(end)] 'end-of-line)
(global-set-key [(C-end)] 'end-of-buffer)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(ansi-color-faces-vector [default bold shadow italic underline bold bold-italic bold])
'(ansi-color-names-vector (vector "#eaeaea" "#d54e53" "#b9ca4a" "#e7c547" "#7aa6da" "#c397d8" "#70c0b1" "#000000"))
'(custom-safe-themes (quote ("82d2cac368ccdec2fcc7573f24c3f79654b78bf133096f9b40c20d97ec1d8016" "1b8d67b43ff1723960eb5e0cba512a2c7a2ad544ddb2533a90101fd1852b426e" "bb08c73af94ee74453c90422485b29e5643b73b05e8de029a6909af6a3fb3f58" "628278136f88aa1a151bb2d6c8a86bf2b7631fbea5f0f76cba2a0079cd910f7d" "06f0b439b62164c6f8f84fdda32b62fb50b6d00e8b01c2208e55543a6337433a" default)))
'(fci-rule-color "#2a2a2a")
'(vc-annotate-background nil)
'(vc-annotate-color-map (quote ((20 . "#d54e53") (40 . "#e78c45") (60 . "#e7c547") (80 . "#b9ca4a") (100 . "#70c0b1") (120 . "#7aa6da") (140 . "#c397d8") (160 . "#d54e53") (180 . "#e78c45") (200 . "#e7c547") (220 . "#b9ca4a") (240 . "#70c0b1") (260 . "#7aa6da") (280 . "#c397d8") (300 . "#d54e53") (320 . "#e78c45") (340 . "#e7c547") (360 . "#b9ca4a"))))
'(vc-annotate-very-old-color nil))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment