.emacs.sample 16.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
;; [CB 10/22/2016]
;; the below file is a sample .emacs file, written for emacs_powerpack.
;; if something is useful to you, keep it.  otherwise, delete it.
;; you may use M-x list-packages to browse and install packages
;; (in emacs-speak, M-x means Alt+x)

;;; *************** PART 1 (BASIC CONFIG) ******************
;;; the config choices in this section to not require any additional emacs packages
;;----- include standard emacs package repos.
(require 'package)
(push '("melpa" . "http://melpa.milkbox.net/packages/")
      package-archives)
(package-initialize)

;;----- broken shutdown of emacs (as on computer crash or force quitting) will leave behind the
;; server directory in .emacs.d.  This function will clean the remnants up so that the emacs "server"
;; functionality starts working again without errors.
(defun clean-serverdir ()
  (interactive)
  (delete-directory "~/.emacs.d/server" t))

;; assuming that there is not incorrect metadata left behind (see doc for clean-serverdir function), this starts
;; up the emacs server.
(require 'server)
(unless (server-running-p)
  (server-start))

;; set the window margins to be smaller (more efficient use of space)
(set-window-margins nil 0 0)

;; I don't really want to see the startup screen every time...
(setq inhibit-startup-message t)

(defun hide-fringes ()
  (set-fringe-mode 0))

(defun show-fringes ()
  (set-fringe-mode 1))

;; fringe styling?
(set-face-attribute 'fringe nil :background "#FFFFFF" :foreground "#000000")

;; don't show the toolbar!  It is generally useless in my opinion.
(tool-bar-mode -1)

;; more sensible scrolling
(setq scroll-step 1) ;; keyboard scroll one line at a time

(setq-default indent-tabs-mode nil)

;; use utf-8! details:
;; http://www.masteringemacs.org/articles/2012/08/09/working-coding-systems-unicode-emacs/
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'prefer-utf-8)
(set-terminal-coding-system 'prefer-utf-8)
(set-keyboard-coding-system 'utf-8)

;; ido mode is nice.  why not use it?
;; (note sometimes ido tries to be too smart when you are searching for a file using C-x C-f. type C-f again in the minibuffer to exit out of ido)
(setq ido-enable-flex-matching t)
(setq ido-everywhere t)
(ido-mode 1)

;; some basic modifications to the menus (feel free to add your own of course!)
;; from emacs "Menu Bar" docs
;; Make a menu keymap (with a prompt string)
;; and make it the menu bar item’s definition.
(define-key-after global-map [menu-bar windows]
  (cons "Windows" (make-sparse-keymap "Windows")))

;;(global-unset-key [menu-bar words])
;;(global-unset-key [menu-bar windows])

;; Define specific subcommands in this menu.
(define-key global-map
  [menu-bar windows onlyone]
  '("Hide others" . delete-other-windows))
(define-key global-map
  [menu-bar windows vsplit]
  '("Vertical split" . split-window-right))
(define-key global-map
  [menu-bar windows hsplit]
  '("Horizontal split" . split-window-below))
(define-key global-map
  [menu-bar windows switchwindows]
  '("Other window" . ace-window))

(define-key-after global-map
  [menu-bar edit insert-char]
  '("Insert Character" . insert-char)
  'props
  )

(put 'narrow-to-region 'disabled nil)
(put 'downcase-region 'disabled nil)

;; ************** PART 2 (Shell Config) ******************
;; shell support on windows is a little messier than it is on Linux/Mac
;; the below code gives you the ability to switch between windows cmd and msys

(require 'shell)

;;we want two shell presets which we can switch between -- windows and msys2 (depending on how things were compiled)
(setf shell-settings-windows (list
                               :path (getenv "PATH")
                                :esfilename explicit-shell-file-name
                                :sfilename shell-file-name
                                :shellenv (getenv "SHELL")
                                :funcstorun (list (lambda () (remove-hook 'comint-output-filter-functions 'comint-strip-ctrl-m))) ))

(setf berry-mingw-fname  "C:/msys64/usr/bin/bash.exe")

(setf shell-settings-mingw (list
                             :path
                             (concat ":/usr/bin:/mingw64/bin:/bin:" "")
;;                                     (replace-regexp-in-string "\\\\" "/"
;;                                                               (replace-regexp-in-string "\\([A-Za-z]\\):" "/\\1"
;;                                                                                         (getenv "PATH"))
;;                                                               t t)
;;                                     )
                             :esfilename berry-mingw-fname
                             :sfilename  berry-mingw-fname
                             :shellenv  berry-mingw-fname
;;                           :funcstorun (list (lambda () (add-hook 'comint-output-filter-functions 'comint-strip-ctrl-m)))
                             ))

(defun switch-shell-configuration (which)
 "which=0 corresponds to mingw, which=1 corresponds to windoze" 
 (interactive "P")
 (let ((settingsvar (cl-case which
                      (0 shell-settings-mingw)
                      (1 shell-settings-windows)
                      (t (throw 'berryerror "unknown value ")))))
   (setenv "PATH" (plist-get settingsvar :path))
   (setf explicit-shell-file-name (plist-get settingsvar :esfilename))
   (setf shell-file-name (plist-get settingsvar :sfilename))
   (setenv "SHELL" (plist-get settingsvar :shellenv))
   (eval (elt (plist-get settingsvar :funcstorun) 0))
   )) 

(defun activate-windows-shell ()
  (interactive)
143
  (switch-shell-configuration 1))
144 145 146

(defun activate-msys-shell ()
  (interactive)
147 148 149 150 151 152 153
  (switch-shell-configuration 0))

;; by default we make "M-x shell" point to msys
;; (if we find msys installed at its default location on the system)
(if (file-exists-p berry-mingw-fname)
    (activate-msys-shell)
  (activate-windows-shell))
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409


;; ***************** PART 3 (Variable Width fonts) *******************
;; this section is disabled by default
;; if you would like to experiment with using variable width fonts, enable it using the below flag
;; enables variable width fonts and various helpful settings relating to using them in conjunction
;; with fixed-width fonts.

(setf *usevariablewidth* nil)
(when *usevariablewidth* 
  ;; the below sets the default emacs font to variable width.  if you want to permanantly switch to fixed with fonts, delete the below.  If you want a certain mode to be associated with fixed-width fonts, you can add a "hook" for that mode (there are some examples below).  If you want to temporarily switch to fixed-width, use the command M-x my-buffer-face-mode-fixed
  (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.
   )
  (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.
   '(default ((t (:family "Arial" :foundry "outline" :slant normal :weight normal :height 120 :width normal)))))

  (defun my-adjoin-to-list-or-symbol (element list-or-symbol)
    (let ((list (if (not (listp list-or-symbol))
                    (list list-or-symbol)
                  list-or-symbol)))
      (require 'cl-lib)
      (cl-adjoin element list)))

  ;; Use variable width font faces in current buffer
  (defun my-buffer-face-mode-variable ()
    "Set font to a variable width (proportional) fonts in current buffer"
    (interactive)
    (setq buffer-face-mode-face '(:family "Arial" :foundry "outline" :slant normal :weight normal :height 120 :width normal))
    (buffer-face-mode))

  ;; Use monospaced font faces in current buffer
  (defun my-buffer-face-mode-fixed ()
    "Sets a fixed width (monospace) font in current buffer"
    (interactive)
    (setq buffer-face-mode-face '(:family "Consolas" :height 110))
    (buffer-face-mode))

  ;; the following modes show up in fixed-width fonts by default!
  (add-hook 'java-mode-hook 'my-buffer-face-mode-fixed)
  (add-hook 'calendar-mode-hook 'my-buffer-face-mode-fixed)
  (add-hook 'c-mode-hook 'my-buffer-face-mode-fixed)
  (add-hook 'slime-popup-buffer-mode-hook 'my-buffer-face-mode-fixed)

  ;; modifications supporting variable width fonts in org mode
  (add-hook 'org-mode-hook 
            (lambda ()
              ;;first, set code, tables, blocks, etc... to use monospace
              (visual-line-mode 1)
              (mapc
               (lambda (face)
                 (set-face-attribute
                  face nil
                  :inherit
                  (my-adjoin-to-list-or-symbol
                   'fixed-pitch
                   (face-attribute face :inherit))))
               (list 'org-code 'org-table 'org-block 'org-block-background 'org-formula))
              ;;(define-key my-org-buffer-local-mode-map (kbd "<f10>") 'some-custom-defun-specific-to-this-buffer)
              ;;(evil-define-key 'normal evil-visual-line-movement-mode-map "j" 'evil-next-visual-line)
              )))

;; *************** PART 4 (External Tools Support) *******************
;; below is sample configuration for various external tools.
;; you will need to modify it to meet your own needs.

;; if you have ace window installed (you should!) we bind a keyboard shortcut.
(when (require 'ace-window nil 'noerror)
  (global-set-key (kbd "C-x o") 'ace-window))

;; babel configuration adding dot (graph language)
(org-babel-do-load-languages
 'org-babel-load-languages
 '((dot . t)
   (emacs-lisp . t))) ; this line activates dot

;; (setq python-shell-interpreter "C:\\Anaconda\\python.exe"
;;      python-shell-interpreter-args "-i C:\\Anaconda\\Scripts\\ipython-script.py console --matplotlib")

(setq python-shell-interpreter "C:\\Python27\\python.exe" )

(setq org-confirm-babel-evaluate nil)

;; (setenv "GS_LIB" "C:/Program Files/gs/gs9.09/lib;")
;; (setq ps-lpr-command "C:/Program Files/gs/gs9.09/bin/gswin64c.exe")
;; (setq ps-lpr-switches '("-q" "-dNOPAUSE" "-dBATCH" "-sDEVICE=mswinpr2"))
;; (setq ps-printer-name t)

;; (setq ps-paper-type 'a4
;;       ps-font-size 7.0
;;       ps-print-header nil
;;       ps-landscape-mode t
;;       ps-number-of-columns 3
;;       ps-line-number nil 
;;       )

                                        ;(require 'org)
                                        ;(require 'ox)
                                        ;
                                        ;(setq org-latex-pdf-process
                                        ;'("pdflatex -interaction nonstopmode -output-directory %o %f" "pdflatex -interaction nonstopmode -output-directory %o %f" "pdflatex -interaction nonstopmode -output-directory %o %f"))
                                        ;
;;  '("latexmk -pdflatex='pdflatex -interaction nonstopmode' -pdf -bibtex -f %f"))

(setq org-export-with-sub-superscripts nil)

;; CB this doesn't appear to actually be enabled on windows.
;; (require 'filenotify)

                                        ;(setq org-clock-persist 'history)
                                        ;(org-clock-persistence-insinuate)

;; if evil is installed, the below code takes effect
(when (require 'evil nil 'noerror)
  (evil-mode 1)
  ;; allowing evil movement commands to work better in org mode
  (evil-define-motion my-0-key-alteration ()
    (if (eql major-mode 'org-mode)
        (evil-beginning-of-visual-line)
      (evil-beginning-of-line)
      ))
  (evil-define-key 'normal org-mode-map  "k" 'evil-previous-visual-line)
  (evil-define-key 'normal org-mode-map "j" 'evil-next-visual-line)
  (evil-define-key 'normal org-mode-map "gj" 'evil-next-line)
  (evil-define-key 'normal org-mode-map "gk" 'evil-previous-line)
  (evil-define-key 'normal org-mode-map "g0" 'evil-beginning-of-line)
  (evil-redirect-digit-argument evil-motion-state-map "0" 'my-0-key-alteration) 
  (evil-define-key 'normal org-mode-map "g$" 'evil-end-of-line)
  (evil-define-key 'normal org-mode-map "$" 'evil-end-of-visual-line))

;; if evil-numbers is installed, the below code takes effect
(when (require 'evil-numbers nil 'noerror)
  (global-set-key (kbd "C-c +") 'evil-numbers/inc-at-pt)
  (global-set-key (kbd "C-c -") 'evil-numbers/dec-at-pt)
  (define-key evil-normal-state-map (kbd "C-c +") 'evil-numbers/inc-at-pt)
  (define-key evil-normal-state-map (kbd "C-c -") 'evil-numbers/dec-at-pt))

(add-hook 'lisp-mode-hook
          (lambda ()
            (set (make-local-variable 'lisp-indent-function)
                 'common-lisp-indent-function)))

;; want to use common lisp?  you will want to modify the below line
(setq inferior-lisp-program "C:/Users/username/directory/ccl-1.10-windowsx86/ccl/wx86cl64.exe")

;; ********************* PART 5 (Programming related functions) ***************************

;;(setq last-kbd-macro
;;   [?i ?h ?i escape ?o ?t ?h ?e ?r ?e escape])

;;(require 'eldoc)
;;(setq debug-on-error t)

(defmacro print-transparent (exp)
  `(let ((tvar987 ,exp)) (message (format "at: %s, '%s'\n" ,(line-number-at-pos) tvar987)) tvar987))

(defmacro print-transparent-2 (note exp)
  `(let ((tvar987 ,exp)) (message (format "%s.  at: %s, '%s'\n" ,(line-number-at-pos) tvar987)) tvar987))


;; *********************** PART 6 (Miscellaneous Commented Examples) ************************
;; these are left here because short examples can be helpful memory aids sometimes.
;; UNUSED
;; (define-minor-mode evil-visual-line-movement-mode 
;;    "Minor mode which provides visual-line movement, primarily intended 
;;     for org mode documents. "
;;    :init-value nil)

;; UNUSED
;; (define-minor-mode  monospace-mode
;;    "Minor mode which provides visual-line movement, primarily intended 
;;     for org mode documents. "
;;    :init-value nil)

;; UNUSED
;; (defun xah-set-font-to-monospace ()
;;  "Change font in current window to a monospaced font."
;;  (interactive)
;;  (set-frame-font "DejaVu Sans Mono" t)
;;  (text-scale-set 0.5)
;;  )

;; UNUSED
;;set up preferred frame sizing.
;; (when window-system          ; start speedbar if we're using a window system
;;    (set-frame-size (selected-frame) 1100 690 t)
;;    (set-frame-position (selected-frame) 215 0)
;;    (speedbar t)
;;    ;(select-frame-by-name "Speedbar 1.0")
;;    ;(set-frame-size (selected-frame) 170 710 t)
;;    ;(set-frame-position (selected-frame) 0 0)
;;    ;(other-frame 1)
;;    )

;; (defun insert-daily-skeleton ()
;;   (interactive)
;;   (let ((currdatestr (format-time-string "%Y-%m-%d")))
;;     (insert (format "
;; *** TIME
;; #+BEGIN: clocktable :maxlevel 5 :scope subtree
;; #+CAPTION: Clock summary at [2016-09-30 Fri 14:53]
;; #+END:

;; **** TASKS
;; ***** task1
;;     CLOCK: [%s 09:30]--[%s 11:00] =>  1:30

;; ***** task2
;;     CLOCK: [%s 11:00]--[%s 15:00] =>  4:00

;; *** NOTES
;; " currdatestr currdatestr currdatestr currdatestr))))

;; (defun insertstuff ()
;;   (interactive)
;;   (cl-loop for i from 13 to 1012 do
;;            (princ (format "(%d,777777,%d),
;; " i i) (current-buffer))
;; ))

;; example of asynchronous process usage
;; from https://curiousprogrammer.wordpress.com/2009/03/27/emacs-comint/
;; (progn
;;   (apply 'make-comint "cmd" "cmd" nil '())
;;   (delete-other-windows)
;;   (switch-to-buffer-other-window "*cmd*")
;;   (other-window -1))

;; (comint-send-string (get-buffer-process "*cmd*") "dir\n")

;; (defun dired-open-file ()
;;   "In dired, open the file named on this line."
;;   (interactive)
;;   (let* ((file (dired-get-filename nil t)))
;;     (message "Opening %s..." file)
;;     (call-process "explorer" nil 0 nil file)
;;     (message "Opening %s done" file)))

;; (defun maximize-frame()
;;   (interactive)
;;   (w32-send-sys-command #xf030)
;; )

;; (defun remove-watermarks ()
;;   (interactive)
;;   (goto-char (point-min))
;;   (while (search-forward "\/Artifact <<\/Subtype \/Watermark")
;;     (kill-whole-line 6)
;;   ))