;;-*-Emacs-Lisp-*-
;; .emacs
;; Sherif Ghali
;; October 2011

;;________________________________________________________________
;;    Determine where we are
;;________________________________________________________________

(defvar system-type-as-string (prin1-to-string system-type))

(defvar on_windows_nt (string-match "windows-nt" system-type-as-string))
(defvar on_darwin     (string-match "darwin" system-type-as-string))
(defvar on_gnu_linux  (string-match "gnu/linux" system-type-as-string))
(defvar on_cygwin     (string-match "cygwin" system-type-as-string))
(defvar on_solaris    (string-match "usg-unix-v" system-type-as-string))

;;________________________________________________________________
;;    Set the elisp path
;;________________________________________________________________

(cond (on_darwin      (setq load-path (cons "~/ghaliweekly/elisp" load-path)) ))
(cond (on_windows_nt  (setq load-path (cons "h:/elisp" load-path)) ))
(cond (on_gnu_linux   (setq load-path (cons "~/elisp" load-path)) ))
(cond (on_cygwin      (setq load-path (cons "/cygdrive/h/elisp" load-path)) ))
(cond (on_solaris     (setq load-path (cons "~/elisp" load-path)) ))

;;________________________________________________________________
;;    General settings
;;________________________________________________________________

;; If we read a compressed file, uncompress it on the fly:
;; (this works with .tar.gz and .tgz file as well)
(auto-compression-mode 1)

;; The following key-binding iconifies a window -- we disable it:
(global-unset-key "\C-x\C-z")
;; The following key-binding quits emacs -- we disable it too:
(global-unset-key "\C-x\C-c")
;; But we establish a longer sequence that is harder to hit by accident:
(global-set-key "\C-x\C-c\C-v" 'save-buffers-kill-emacs)
;; The longer sequence is all right: emacs should be launched just
;; once at login and never killed until ready to logout.

;; C-x j, which is bound to kanji entering, is too close to dired's C-x C-j
(global-unset-key "\C-xj")

;; Disable binding of C-z to iconify a window.
(global-unset-key "\C-z")

;; M-` invokes tmm-menubar; disable it.
(global-unset-key "\M-`")

;; C-x C-n invokes set-goal-column; disable it.
(global-unset-key "\C-x\C-n")

;; We use C-c C-z to invoke a shell inside emacs.
;; The benefits of running a shell from emacs (rather than in an xterm) are:
;;   - It is possible to cycle through the previous commands
;;     and edit them using the usual emacs commands
;;   - One completely avoids using the mouse
;;   - The commands are fontified, which makes it easy to identify, for example,
;;     the command line options.
;;   - There is no upper bound on the output size: Everything is saved.
;;     This of course requires caution, but has the benefit of allowing
;;     the usual search commands in the shell window.
(global-set-key "\C-c\C-z" 'eshell)

;; prevent down-arrow from adding empty lines to the bottom of the buffer
;; (which is the default behaviour)
(setq next-line-add-newlines nil)

;; To make it possible for M-q (fill-paragraph) to end a line with a period,
;; one needs to tell emacs to abandon its convention of distinguishing between
;; single and double space.
(setq sentence-end-double-space nil)

;;________________________________________________________________
;;    Flash the screen on error; don't beep.
;;________________________________________________________________

(setq-default visible-bell t)

;;________________________________________________________________
;;    More Misc
;;________________________________________________________________

;; Highlight the marked region.
(setq-default transient-mark-mode t)

;; 'woman' mode is an improvement on 'man' mode for manual pages
(setq-default woman-use-own-frame nil)
;; Man-notify-method controls the behaviour of (wo)man mode.
(setq-default Man-notify-method 'pushy)

;; Permanent display of line and column numbers is handy.
(setq-default line-number-mode 't)
(setq-default column-number-mode 't)

;;________________________________________________________________
;;    Font lock
;;________________________________________________________________

;; Use font-lock everywhere.
(global-font-lock-mode t)

;; We have CPU to spare; highlight all syntax categories.
(setq font-lock-maximum-decoration t)

;; It is much more pleasant and less tiring to use a dark background.
(set-foreground-color "white")
(set-background-color "black")

;; Set cursor and mouse colours:
(set-cursor-color "yellow")
(set-mouse-color "white")

;;________________________________________________________________
;;    Choose a font that provides 60-80 lines.
;;________________________________________________________________

(cond (on_darwin
       (set-default-font "-apple-monaco-medium-r-normal--14-*-*-*-*-*-*-*")
       ;; (set-default-font "-apple-monaco-medium-r-normal--12-120-72-72-m-120-iso10646-1")
       ;; (set-default-font "-apple-monaco-medium-r-normal--13-130-72-72-m-130-iso10646-1")
       ;; (set-default-font "-apple-monaco-medium-r-normal--14-140-72-72-m-140-iso10646-1")
       ;;   (set-default-font "-apple-monaco-medium-r-normal--18-*-*-*-*-*-*-*")
       ;;   (set-default-font "-apple-monaco-medium-r-normal--24-*-*-*-*-*-*-*")
       ;;   (set-default-font "-apple-monaco-medium-r-normal--36-*-*-*-*-*-*-*")
))

(cond (on_windows_nt
       ;; (set-default-font "Lucida Console-9:bold")
       (set-default-font "Lucida Console-11:bold")
       ;; (set-default-font "Lucida Console-13:bold")
       ;; (set-default-font "Lucida Console-15:bold")
       ;; (set-default-font "Consolas-12")
       ;; (set-default-font "Courier New-12:bold")
))

(cond (on_gnu_linux
       (set-default-font "9x15bold")
       ;; (set-default-font "12x24")
))

(cond (on_cygwin
       (set-default-font "9x15bold")
))

;;________________________________________________________________
;;    I hardly ever use the menu bar or the tool bar
;;________________________________________________________________
;; Asking for no menu bar on OS X/Darwin is harmless, but also futile.
(cond (on_windows_nt
       (menu-bar-mode -1)
))
(when window-system
  (tool-bar-mode -1)
)
;; remember that speedbar, on the other hand, is useful

;;________________________________________________________________
;;    Settings for new frames (make-frame-command, C-x 5 2)
;;________________________________________________________________
(setq default-frame-alist
      '((background-color . "black")
        (foreground-color . "white")
        (scroll-bar-foreground-color . "red")
        (vertical-scroll-bars . right)
        (scroll-bar-width . 17)
        (top . 20)
        (left . 10)
        (width . 140)
        ;;			    (height . 50) ;; for laptop
        (mouse-color . "yellow")
        (cursor-color . "yellow")))

(cond (on_windows_nt
       (setq default-frame-alist
             (append default-frame-alist 
                     '((font . "Lucida Console-11:bold")
                       (height . 64)
                       (width . 140)
                       )))
))

(cond (on_darwin
       (setq default-frame-alist
             (append default-frame-alist 
                     '((font . "-apple-monaco-medium-r-normal--14-*-*-*-*-*-*-*")
                       (width . 130)
                       (height . 39)
                       ;;	(height . 58) too large for MacBook's 1280x800
                       )))
       ))

(cond (on_gnu_linux
       (setq default-frame-alist
             (append default-frame-alist 
                     '((font . "9x15bold")
                       (width . 130)
                       (height . 38)
                       )))
       ))

(cond (on_solaris
       (setq default-frame-alist
             (append default-frame-alist
                     '((width . 130)
                       (height . 38)
                       )))
       ))

;; notice that 
;;    toggle-horizontal-scroll-bar
;; reports
;;    toggle-horizontal-scroll-bar: Horizontal scroll bars aren't implemented yet

;;________________________________________________________________
;;    Use the following settings for the initial frame.
;;________________________________________________________________

(setq initial-frame-alist
      '((top . 20)
        (left . 10)
        (width . 140)
        (height . 39) ))

;;________________________________________________________________
;;    Files and directories
;;________________________________________________________________

;; dired-x is a nice substitute for Windows Explorer and OSX's Finder.
;; M-o: avoid seeing all the backup files.
;; C-x C-j: enter dired/dired-x mode.
(add-hook 'dired-load-hook
	  (function (lambda ()
		      (load "dired-x"))))


;; Because Explorer and Finder have a mapping from file type to application,
;; we need to tell emacs what to do with each file type.

(setq dired-guess-shell-alist-user
      (list
       (list "\\.ipe$"    "ipe ")
       (list "\\.xml$"    "ipe ")
       (list "\\.prn$"    "gv ")
       (list "\\.ps$"     "gv ")
       (list "\\.ps.gz$"  "gv ")
       (list "\\.eps$"    "gv ")
       (list "\\.eps.gz$" "gv ")
       (list "\\.pdf$"    "acroread")
       (list "\\.PDF$"    "acroread")
       (list "\\.iv$" "SceneViewer")
       (list "\\.\\(rgb\|tiff\|tif\|xbm\|gif\|pgm\|ppm\|bmp\|tga\\)$"  "display")
       (list "\\.ppm$" "display")
       (list "\\.gif$" "display")
       (list "\\.png$" "display")
       (list "\\.jpg$" "display")
       (list "\\.JPG$" "display")
       (list "\\.avi$" "movieplayer")
       (list "\\.sc$" "showcase")
       (list "\\.wav$" "realplay")
       (list "\\.drawtool$" "drawtool")
       ))

;;________________________________________________________________
;;    Define a few colours that look good on reverse video:
;;________________________________________________________________

(set-face-foreground 'bold "LightGoldenrod")
(set-face-background 'bold "grey20")

(set-face-foreground 'bold-italic "yellow green")

(set-face-foreground 'italic "yellow3")

(set-face-background 'region "DarkSlateGrey")

(set-face-foreground 'isearch "white")
(set-face-background 'isearch "SteelBlue3")

(set-face-foreground 'font-lock-comment-face "green")
(set-face-background 'font-lock-comment-face "black")

(set-face-foreground 'font-lock-string-face "LightSalmon")
(set-face-background 'font-lock-string-face "black")

(set-face-foreground 'font-lock-doc-face "LightSalmon2")
(set-face-background 'font-lock-doc-face "black")
;; font-lock-doc-face inherits font-lock-string-face.

(set-face-foreground 'font-lock-function-name-face "gold")
(set-face-background 'font-lock-function-name-face "gray10")
;; dired-directory inherits font-lock-function-name-face.

(set-face-foreground 'font-lock-variable-name-face "LightGoldenrod")
(set-face-background 'font-lock-variable-name-face "black")

(set-face-foreground 'font-lock-keyword-face "gold")
(set-face-background 'font-lock-keyword-face "black")

;; Face: font-lock-type-face
;; Documentation: Font Lock mode face used to highlight types and classes.
(set-face-foreground 'font-lock-type-face "cyan")

(set-face-foreground 'modeline "black")
(set-face-background 'modeline "SteelBlue2") ;; "#5cacee"

(set-face-foreground 'highlight "black")
(set-face-foreground 'secondary-selection "black")

;;          Green	#00ff00
;;   LightSalmon2	#ee9572	238,149,114
;;           gold	#ffd700	255,215,0
;;         gray15	#262626
;; LightGoldenrod	#eedd82
;;     SteelBlue2	#5cacee	92,172,238
;;  DarkSlateGrey	#2f4f4f
;;     LightBlue2
;;     SteelBlue2

;;________________________________________________________________
;;    Settings for compilation 
;;________________________________________________________________

;; We set a key-binding for this often-used command:
(global-set-key "\M-C" 'compile)
;; Notice that by default 'compile calls "make -k"

;; The following two commands load the source file automatically and point
;; to the error/warning line. This make emacs essentially a (mouse-free) IDE:
(global-set-key [f11] 'previous-error)
(global-set-key [f12] 'next-error)

;;________________________________________________________________
;;    Settings for compilation scrolling
;;________________________________________________________________

;; scroll the *compilation* buffer window as output appears. 
(setq compilation-scroll-output t) 
;; (setq compilation-window-height 20)
(setq compile-auto-highlight t)

;;________________________________________________________________
;;    Set the default compilation command
;;________________________________________________________________

;; default on *nix is 'make -t'

(cond (on_windows_nt    (setq compile-command "nmake") ))
(cond (on_darwin        (setq compile-command "make ") ))
(cond (on_gnu_linux     (setq compile-command "make ") ))
(cond (on_solaris       (setq compile-command "make ") ))

;;________________________________________________________________
;;    Compile without pressing enter to confirm command
;;________________________________________________________________

;; (setq compilation-read-command nil)
;; 
;; This is a bad idea:
;;     1- It precludes using qmake as a variant.
;;     2- It is mildly risky if the compile command becomes somehow corrupted.

;;________________________________________________________________
;;    Settings for modes
;;________________________________________________________________

;;________________________________
;;    c++-mode
;;________________________________

;; Even if the file extension is just .c or .h, assume it is a C++ file:
(setq auto-mode-alist (cons '("\\.c\\'" . c++-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.h\\'" . c++-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.fx\\'" . c++-mode) auto-mode-alist))

;; Treat vertex and fragment shaders as C programs
(setq auto-mode-alist (cons '("\\.fsh\\'" . c-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.vsh\\'" . c-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.vert\\'" . c-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.frag\\'" . c-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.vert.txt\\'" . c-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.frag.txt\\'" . c-mode) auto-mode-alist))

;; Accept more filenames as Makefiles.
(setq auto-mode-alist (cons '(".*Makefile.*" . makefile-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.mak" . makefile-mode) auto-mode-alist))

;; Treat .rhtml files as HTML
(setq auto-mode-alist (cons '("\\.rhtml\\'" . html-mode) auto-mode-alist))

;;________________________________
;;    ruby-mode
;;________________________________

(setq ruby-indent-level 4)
;; Treat .rjs files as Ruby
(setq auto-mode-alist (cons '("\\.rjs\\'" . ruby-mode) auto-mode-alist))
;; Rakefiles are Ruby files:
(setq auto-mode-alist (cons '("\\Rakefile\\'" . ruby-mode) auto-mode-alist))
;; So is Gemfile:
(setq auto-mode-alist (cons '("\\Gemfile\\'" . ruby-mode) auto-mode-alist))

;; Treat .vssettings files (Visual Studio) as XML
(setq auto-mode-alist (cons '("\\.vssettings\\'" . xml-mode) auto-mode-alist))

;;________________________________
;;    Finance
;;________________________________
;; Treat .fixlog files (FIX) as XML -- large files; use on demand
;; (setq auto-mode-alist (cons '("\\.fixlog\\'" . xml-mode) auto-mode-alist))
;; or else: don't font-lock fixlog files
;; (setq auto-mode-alist (cons '("\\.fixlog\\'" . fundamental-mode) auto-mode-alist))

;; Treat .ssql files (Streambase) as SQL
(setq auto-mode-alist (cons '("\\.ssql\\'" . sql-mode) auto-mode-alist))

;;________________________________
;;    lua-mode
;;________________________________

;; http://lua-mode.luaforge.net/

(setq auto-mode-alist (cons '("\\.lua$" . lua-mode) auto-mode-alist))
(autoload 'lua-mode "lua-mode" "Lua editing mode." t)
;; If you want to use hideshow, turn on hs-minor-mode or add this:
;; (add-hook 'lua-mode-hook 'hs-minor-mode)

;;________________________________
;;    Boost jam-mode
;;________________________________

(cond (on_windows_nt
       (require 'jam-mode)
       (add-to-list 'auto-mode-alist '("\\.jam$" . jam-mode))
       (add-to-list 'auto-mode-alist '("^Jamfile$\\|^Jamfile\\.v2$" . jam-mode))
))

;;________________________________
;;    DOS batch files
;;________________________________
(cond (on_windows_nt
       (autoload 'dos-mode "dos" "Edit Dos scripts." t)
       (add-to-list 'auto-mode-alist '("\\.bat$" . dos-mode))
))

;;________________________________
;;    lilypond-mode
;;________________________________

;; http://lilypond.org/doc/v2.11/Documentation/user/lilypond-program/Emacs-mode

(cond (on_darwin
       (setq load-path
             (append (list
                      (expand-file-name
                       "~/ghaliweekly/elisp/lily")) load-path))
;;                       "/Applications/LilyPond.app/Contents/Resources/share/emacs/site-lisp")) load-path))

       (autoload 'LilyPond-mode "lilypond-mode" "LilyPond Editing Mode" t)
       (add-to-list 'auto-mode-alist '("\\.ly$" . LilyPond-mode))
       (add-to-list 'auto-mode-alist '("\\.ily$" . LilyPond-mode))
       (add-hook 'LilyPond-mode-hook (lambda () (turn-on-font-lock)))
))

;;________________________________
;;    qt-pro-mode
;;________________________________

;; http://www.tolchz.net/2008/01/07/qmake-major-mode-for-emacs-qt-proel/

;; Use for Qt's .pro and .pri files
(if on_gnu_linux
     ()
     (progn (require 'qt-pro)
	    (add-to-list 'auto-mode-alist '("\\.pr[io]$" . qt-pro-mode)))
)

;; Treat .moc files (Qt) as C++
;; (setq auto-mode-alist (cons '("\\.moc\\'" . c++-mode) auto-mode-alist))
;; Nokia/Trolltech renamed moc files to moc_*.cpp. Pattern added to dired-omit.

;; Treat .ui files (Qt) as XML
(setq auto-mode-alist (cons '("\\.ui\\'" . xml-mode) auto-mode-alist))

;;________________________________
;;    Old:
;;    Qt mode from:
;;    http://www.emacswiki.org/emacs/QtMode
;;________________________________

;;(require 'cc-mode)
;;  (setq c-C++-access-key "\\<\\(slots\\|signals\\|private\\|protected\\|public\\)\\>[ \t]*[(slots\\|signals)]*[ \t]*:")
;;  (font-lock-add-keywords 'c++-mode '(( (concat "\\<\\(Q_OBJECT\\|public slots\\|public signals\\|private slots\\|"
;;                                                "private signals\\|protected slots\\|protected signals\\)\\>") . font-lock-constant-face)))

;;________________________________
;;    Ruby on Rails
;;________________________________

;; Emacs has one serious weakness. There is no way to use font-lock in
;; a file mixing two languages. A literate program mixing C code with
;; LaTeX is one example. An rhtml file mixing Ruby and HTML is
;; another.

;;(cond (on_darwin
;;       (setq load-path (cons "~/ghaliweekly/elisp/emacs-rails" load-path))
;;       (setq load-path (cons "~/ghaliweekly/elisp/emacs-rails-extra" load-path))
;;
;;       (defun try-complete-abbrev (old)
;;         (if (expand-abbrev) t nil))
;;
;;       (setq hippie-expand-try-functions-list
;;             '(try-complete-abbrev
;;               try-complete-file-name
;;               try-expand-dabbrev))
;;
;;       (require 'rails)
;;
;;       (setq auto-mode-alist  (cons '("\\.rhtml$" . html-mode) auto-mode-alist))
;;))

;;________________________________
;;    javascript-mode
;;________________________________

(setq auto-mode-alist (cons '("\\.js\\'" . java-mode) auto-mode-alist))

;; no good:
;;(autoload 'javascript-mode "javascript-mode")
;;(setq auto-mode-alist
;;      (cons '("\\.js\\'" . javascript-mode) auto-mode-alist))

;; ________________________________
;;    xml-mode
;; ________________________________

(setq auto-mode-alist (cons '("\\.ipe\\'" . xml-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.qrc\\'" . xml-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.svg\\'" . xml-mode) auto-mode-alist))

;;________________________________________________________________
;;    Scrolling
;;________________________________________________________________

;; We also map scroll wheel and trackpad events to scrolling.
;; The mouse wheel on windows generates few events.
;; Scroll by 3 unless shifted.

(defun up-slow () (interactive) (scroll-up 1))
(defun down-slow () (interactive) (scroll-down 1))

(defun up-semi-slow () (interactive) (scroll-up 2))
(defun down-semi-slow () (interactive) (scroll-down 2))

(defun up-medium () (interactive) (scroll-up 3))
(defun down-medium () (interactive) (scroll-down 3))

(cond (on_windows_nt
       ;; xemacs won't like the following:
       (global-set-key [mouse-4] 'down-medium)
       (global-set-key [mouse-5] 'up-medium)

       (global-set-key [S-mouse-4] 'down-slow)
       (global-set-key [S-mouse-5] 'up-slow)
))

;; The trackpad on Mac OSX generates too many events.
;; Scroll by 1 unless shifted.
(cond (on_darwin
       (global-set-key [mouse-4] 'down-slow)
       (global-set-key [mouse-5] 'up-slow)

       (global-set-key [S-mouse-4] 'down-medium)
       (global-set-key [S-mouse-5] 'up-medium)
))

(cond (on_gnu_linux
       (global-set-key [mouse-4] 'down-medium)
       (global-set-key [mouse-5] 'up-medium)

       (global-set-key [S-mouse-4] 'down-slow)
       (global-set-key [S-mouse-5] 'up-slow)
))

(defun up-fast () (interactive) (scroll-up 8))
(defun down-fast () (interactive) (scroll-down 8))
(global-set-key [C-mouse-4] 'down-fast)
(global-set-key [C-mouse-5] 'up-fast)

;; Ordinarily emacs jumps by half a page when scrolling -- reduce:
(setq scroll-step 1)

;; The default value is 5, which is too fast on a MacBook or a trackpad; reduce:
(cond (on_darwin
       (mouse-wheel-mode 1)
       (setq mouse-wheel-scroll-amount '(1 ((shift) . 1) ((control) . nil)))
       (setq mouse-wheel-progressive-speed 'f)
))

;; And finally, the most useful addition to .emacs: the ability to
;; scroll from the keyboard (what is everyone else using!?)
(global-set-key "\M-N" 'up-semi-slow)
(global-set-key "\M-P" 'down-semi-slow)

;;________________________________________________________________
;;    Calendar
;;________________________________________________________________

(setq calendar-latitude [43 40 north])
(setq calendar-longitude [79 24 west])
(setq calendar-time-zone -300)
(setq calendar-location-name "Toronto")

;;________________________________________________________________
;;    Dired-mode settings
;;________________________________________________________________

;; A few customizations:
;; Among them: make copy and delete in dired recursive.

(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.
 '(dired-recursive-copies (quote top))
 '(dired-recursive-deletes (quote top))
 '(large-file-warning-threshold 100000000)
 '(mumamo-submode-indent-offset 4)
 '(same-window-buffer-names (quote ("*eshell*" "*Python*" "*shell*"
                                    "*mail*" "*inferior-lisp*"
                                    "*ielm*" "*scheme*" "*"))))

;;________________________________________________________________
;;    Local Variable Values
;;________________________________________________________________

;; May need:
;; (TeX-brace-indent-level . 4) (TeX-auto-untabify)
;; (TeX-auto-regexp-list . LaTeX-auto-regexp-list))))

;;________________________________________________________________
;;    Dired omit
;;        dired-omit-files is only effective if emacs is restarted.
;;________________________________________________________________

(add-hook 'dired-mode-hook
          (lambda ()
            (setq dired-omit-files
                  (concat "^\\.$\\|"
                          "^\\.\\.$\\|"
                          "^\\.git$\\|"
                          "^moc_\\|"
                          "\\.d$\\|"
                          "\\.ncb$\\|"
                          "\\.sln$\\|"
                          "\\.suo$\\|"
                          "^vc90\\|"
                          "\\.pdb$\\|"
                          "^vc90\\.idb$\\|"
                          "^Jamfile$\\|"
                          "^Jamfile\\.v2$\\|"
                          "^Makefile$\\|"
                          "^Makefile\\.Debug$\\|"
                          "^Makefile\\.Release$\\|"
                          "\\.vcproj$\\|"
                          "\\.vcproj\\.NA\\.ghali\\.user$"))
            ))

;; We don't hide \\|^debug$\\|^release$ to keep it possible to run (! or &) executables from emacs.
;; 
;; Do not set
;;     dired-omit-extensions
;; directly. See below.

;;________________________________________________________________
;;    Completion
;;________________________________________________________________

'(completion-ignored-extensions
  (quote ("CVS/" ".o" "~" ".bin" ".lbin" ".fasl" ".ufsl" ".a" ".ln" ".blg" ".bbl"
          ".elc" ".lof" ".glo" ".idx" ".lot" ".dvi" ".fmt" ".tfm" ".class" ".fas"
          ".lib" ".x86f" ".sparcf" ".lo" ".la" ".toc" ".log" ".aux" ".cp" ".fn"
          ".ky" ".pg" ".tp" ".vr" ".cps" ".fns" ".kys" ".pgs" ".tps" ".vrs" ".lbl"
          ".out" ".brf" ".ncb" ".sln" ".suo" ".vcproj.AD.ghali.user" ".idb" ".pdb"
          ".synctex.gz" ".svn")))

;;       .vcproj.AD.ghali.user
;; client.vcproj.AD.ghali.user

;; dired-omit-extensions defaults to elements of
;;     `completion-ignored-extensions'
;;     `dired-latex-unclean-extensions'
;;     `dired-bibtex-unclean-extensions'
;;     `dired-texinfo-unclean-extensions'


;;________________________________________________________________
;;    Avoid vertical splits
;;________________________________________________________________
;; If a window is wider than split-width-threshold, Emacs will split a
;; window horizontally (C-x 3) when one compiles. Since my preferred
;; default is to truncate-lines, it means that I have to scroll
;; horizontally to read the error messages. Change the variable to
;; something half of which makes it possible to read compilation
;; messages.

(setq split-width-threshold 240)

;;________________________________________________________________
;;    Function definitions (bound to function keys)
;;________________________________________________________________

(defun altotop () "Align at Top of Screen" (interactive) (recenter 1))
;; now that recenter-top-bottom is C-l, use F7 for something other than (recenter 1).
(defun funcsumm () "function summary" (interactive)
  (occur  "^void\\|int [a-zA-Z_]*([^$])[^;]$"))
;;  (occur  "\(void\|int\) *"))
(defun ptreg1 () "Save Current Location" (interactive) (point-to-register 1))
(defun gtreg1 () "Goto Saved Location" (interactive) (jump-to-register 1))
(defun ptreg2 () "Save Current Location" (interactive) (point-to-register 2))
(defun gtreg2 () "Goto Saved Location" (interactive) (jump-to-register 2))
(defun ptreg3 () "Save Current Location" (interactive) (point-to-register 3))
(defun gtreg3 () "Goto Saved Location" (interactive) (jump-to-register 3))
(defun ptreg4 () "Save Current Location" (interactive) (point-to-register 4))
(defun gtreg4 () "Goto Saved Location" (interactive) (jump-to-register 4))

;;________________________________________________________________
;;    Function Key binding
;;________________________________________________________________

(global-set-key [f1] 'goto-line)
(global-set-key [f2] 'what-line)

(global-set-key [S-f3] 'ptreg1)
(global-set-key [f3] 'gtreg1)
(global-set-key [S-f4] 'ptreg2)
(global-set-key [f4] 'gtreg2)
(global-set-key [S-f5] 'ptreg3)
(global-set-key [f5] 'gtreg3)
(global-set-key [S-f6] 'ptreg4)
(global-set-key [f6] 'gtreg4)

(global-set-key [f7] 'altotop)
(global-set-key [S-f7] 'eval-region)

;; (global-set-key [f8] 'funcsumm)
(global-set-key [f8] 'bury-buffer)
(global-set-key [S-f8] 'unbury-buffer)

;; (global-set-key [S-f8] 'brf-FindNextDbl)

;; We also set [M-f8] below to hs-toggle-hiding

(global-set-key [M-f9] 'shrink-window)
(global-set-key [M-f10] 'enlarge-window)

;; (global-set-key [f9] 'delete-other-windows) ; ^x 1
;; (global-set-key [f10] 'other-window)	; ^x o

(global-set-key [f11] 'previous-error)
(global-set-key [f12] 'next-error)

;; windows doesn't send S-f3 but f13 so we define those:
(global-set-key [f13] 'ptreg1)
(global-set-key [f14] 'ptreg2)
(global-set-key [f15] 'ptreg3)
(global-set-key [f16] 'ptreg4) ;; interesting; by default it maps to <print>.
(global-set-key [f17] 'eval-region)

;;________________________________________________________________
;;    Insert hard newlines while typing in text mode
;;________________________________________________________________

(add-hook 'text-mode-hook '(lambda () (auto-fill-mode 1)))
(add-hook 'mail-mode-hook '(lambda () (auto-fill-mode 1)))
(add-hook 'latex-mode-hook '(lambda () (auto-fill-mode 1)))

;;________________________________________________________________
;;    Put all .save's in one place
;;________________________________________________________________

(cond (on_darwin
       (setq auto-save-list-file-prefix "~/ghaliweekly/misc/.save/.saves-" )
))

;;________________________________________________________________
;;    Info
;;________________________________________________________________

(cond (on_windows_nt
       (setq Info-directory-list
             (cons 
              (expand-file-name "C:/cygwin17/usr/share/info/")
              Info-default-directory-list))
))

;; Other places to look for info files:
;; setenv INFOPATH /usr/gnu/info:/usr/local/info:/usr/TeX/info
;; /usr/share/info/

;;________________________________________________________________
;;    fontify html 
;;________________________________________________________________

;; even though emacs > 21.xx.xx has an html mode, htmlfontify is
;; useful because it makes it possible to 
;;    M-x htmlfontify-copy-and-link-dir

(cond (on_darwin
       (when (< emacs-major-version 23)
         (setq load-path (cons "~/ghaliweekly/elisp/htmlfontify" load-path))
         (require 'htmlfontify)
)))

;;________________________________________________________________
;;    Stop cursor from blinking
;;________________________________________________________________

;; Starting from emacs 21, the default cursor blinks.

(when (>= emacs-major-version 21)
  (blink-cursor-mode 0)
)

;;________________________________________________________________
;;    Some dired settings
;;________________________________________________________________
(cond (on_darwin
        (require 'dired)

        (define-key dired-mode-map "o" 'dired-open-mac)
        (defun dired-open-mac ()
          (interactive)
          (let ((file-name (dired-get-file-for-visit)))
            (if (file-exists-p file-name)
                (shell-command (concat "open '" file-name "'" nil )))))
))

;; Q: How does one do dired-open on Windows?

;; Emacs 22 already had dired-toggle-read-only, but it was called
;; wdired-change-to-wdired-mode
;; We override C-x C-q. Its previous binding in emacs 22 is
;; toggle-read-only.
;; This makes it possible to rename files by editting the dired buffer.
(when (= emacs-major-version 22)
  (require 'dired)
  (define-key dired-mode-map "\C-x\C-q" 'wdired-change-to-wdired-mode)
)

;;________________________________________________________________
;;    CVS
;;________________________________________________________________

(setenv "CVS_RSH" "ssh")

;;________________________________________________________________
;;    Latex
;;________________________________________________________________

;; Notice that MacTeX installs to /usr/local/texlive.
;; 'port install texlive' would be in /opt/local/*
;; Avoid having a duplicate tex installation.

(cond (on_darwin
       (setenv "TEXINPUTS"
               ".:/usr/local/texlive/2011/texmf-dist/tex//:"
               "$HOME/ghaliweekly/latex/styles//")
))

;; If I return to installing LaTeX via MacPorts, reset to:
;;     (setenv "TEXINPUTS" ".:/opt/local/share/texmf-dist/tex//")

;;________________________________________________________________
;;    Path
;;________________________________________________________________

(cond (on_darwin
       (setenv "PATH" (concat ".:/usr/local/Trolltech/Qt-4.8.0/bin:"
                              "/usr/texbin:"
                              "/opt/local/bin:"
                              "/opt/local/sbin:"
                              "$HOME/ghali/bin/scripts:"
                              "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:"
                              "/usr/local/texlive/2011/bin/universal-darwin/"))

       (setenv "DYLD_LIBRARY_PATH" "/usr/local/glow/glow_src/:/usr/local/ipe/build/lib/")

       (setenv "PKG_CONFIG_PATH" "/usr/local/Trolltech/Qt-4.8.0/lib/pkgconfig")
))

(cond (on_windows_nt
       (setenv "INCLUDE"
	       (concat "C:/Program Files/Microsoft Visual Studio 9.0/VC/ATLMFC/INCLUDE;"
                       "C:/Program Files/Microsoft Visual Studio 9.0/VC/INCLUDE;"
                       "C:/Program Files//Microsoft SDKs/Windows/v6.0A/include"))
       ;; ;C:/Program Files/Microsoft Visual Studio .NET 2003/SDK/v1.1/include/


       (setenv "LIB"
	       (concat "C:/Program Files/Microsoft Visual Studio 9.0/VC/ATLMFC/LIB;"
                       "C:/Program Files/Microsoft Visual Studio 9.0/VC/LIB;"
                       "C:/Program Files//Microsoft SDKs/Windows/v6.0A/lib"))
       ;; ;C:/Program Files/Microsoft Visual Studio .NET 2003/SDK/v1.1/Lib/


       (setenv "LIBPATH"
	       (concat "C:/WINNT/Microsoft.NET/Framework/v3.5;C:/WINNT/Microsoft.NET/Framework/v2.0.50727;"
                       "C:/Program Files/Microsoft Visual Studio 9.0/VC/ATLMFC/LIB;"
                       "C:/Program Files/Microsoft Visual Studio 9.0/VC/LIB"))

       ;; (setenv "PATH" "C:/Program Files/Microsoft Visual Studio 9.0/VC/bin/")

       (setenv "PATH"
	       (concat "C:/Program Files/Microsoft Visual Studio 9.0/Common7/IDE;"
                       "C:/Program Files/Microsoft Visual Studio 9.0/VC/BIN;"
                       "C:/Program Files/Microsoft Visual Studio 9.0/Common7/Tools;"
                       "C:/WINNT/Microsoft.NET/Framework/v3.5;"
                       "C:/WINNT/Microsoft.NET/Framework/v2.0.50727;"
                       "C:/Program Files/Microsoft Visual Studio 9.0/VC/VCPackages;"
                       "C:/Program Files//Microsoft SDKs/Windows/v6.0A/bin;"
                       "C:/Qt/4.7.1/bin;C:/WINNT/system32;C:/WINNT;C:/WINNT/system32/WBEM;"
                       "C:/Program Files/Common Files/OTG;C:/cygwin17/bin"))
))

(cond (on_gnu_linux
       (setenv "PATH"
	       (concat "/usr/kerberos/bin:"
                       "/usr/local/bin:"
                       "/bin:"
                       "/usr/bin:"
                       "/apps/home/ghali/bin:"
                       "/usr/local/Trolltech/Qt-4.7.1/bin:"
                       "."))
))

(cond (on_solaris
       (setenv "PATH"
               (concat "/usr/bin:"
                       "/usr/ccs/bin:"
                       "/usr/local/bin:"
                       "/usr/sfw/bin:"
                       "."))

       (setenv "LD_LIBRARY_PATH"
               (concat "/home/ghali/boost_1_45_0/stage/lib:"
                       "/home/ghali/qt/lib:"
                       "."))
))

;;________________________________________________________________
;;    eshell path
;;________________________________________________________________

(cond (on_windows_nt
       (add-hook 'eshell-mode-hook
		 '(lambda nil
		    (eshell/export "EPOCROOT=\\Paragon\\")
		    (let ((path))

		      (setq path (concat "C:/Program Files/Microsoft Visual Studio 9.0/Common7/IDE"
                                         ";C:/Program Files/Microsoft Visual Studio 9.0/VC/bin"
                                         ";C:/Program Files/Microsoft Visual Studio 9.0/VC/BIN"
                                         ";C:/Program Files/Microsoft Visual Studio 9.0/Common7/Tools"
                                         ";C:/WINNT/Microsoft.NET/Framework/v3.5"
                                         ";C:/WINNT/Microsoft.NET/Framework/v2.0.50727"
                                         ";C:/Program Files/Microsoft Visual Studio 9.0/VC/VCPackages"
                                         ";C:/Program Files//Microsoft SDKs/Windows/v6.0A/bin"
                                         ";C:/Qt/4.7.1/bin"
                                         ";C:/WINNT/system32"
                                         ";C:/WINNT"
                                         ";C:/WINNT/system32/WBEM"
                                         ";C:/Program Files/Common Files/OTG"
                                         ";C:/cygwin17/bin"))
		      (setenv "PATH" path))
		    (local-set-key "\C-u" 'eshell-kill-input))
		 )
))

(cond (on_darwin
       (add-hook 'eshell-mode-hook
		 '(lambda nil
		    (eshell/export "EPOCROOT=\\Paragon\\")
		    (let ((path))

		      (setq path (concat "/Users/me/.rvm/bin/rvm"
                                         ";/Users/me/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/bin"
                                         ";/opt/local/bin"
                                         ))
		      (setenv "PATH" path))
		    (local-set-key "\C-u" 'eshell-kill-input))
		 )
))

;;________________________________________________________________
;;    Qt & Visual Studio
;;________________________________________________________________

(cond (on_windows_nt
       (setenv "QTDIR" "C:\Qt\4.7.1")
       (setenv "QMAKESPEC" "win32-msvc2008")
))

;; Setting QMAKESPEC avoids:
;; Warning: Generator: MSVC.NET: Found more than one version of
;; Visual Studio, but none in your path! Fallback to lowest
;; version (MSVC.NET 2008 (9.0), MSVC.NET 2003 (7.1))

;;________________________________________________________________
;;    pgp/gnupg encrypt
;;________________________________________________________________

;; file extension: .cpt
(if on_gnu_linux
    ()
  (require 'ps-ccrypt "ps-ccrypt.el")
)

;;________________________________________________________________
;;    Change window title
;;________________________________________________________________

(setq frame-title-format
      (list ""
	    "%b"
;;	    " of "
;;	    `default-directory
	    " @ "
	    system-name
            " ("
            system-type-as-string
            ")"
      ))

;;________________________________________________________________
;;    Do not publish my email on Usenet
;;________________________________________________________________

(setq user-full-name       "Sherif Ghali")
;; (setq user-login-name      "myLastname")
;; (setq user-real-login-name "myLastname")
;; (setq user-mail-address    "myName@somewhere")
;; (setq system-name          "machine.somewhere")

;;________________________________________________________________
;;    Don't display initial logo
;;________________________________________________________________

(setq inhibit-startup-message t)

;;________________________________________________________________
;;    SVN
;;________________________________________________________________

;; The executable is Cygwin's, but we can use it on bare windows.
(cond (on_windows_nt
       (require 'psvn)
       (setq svn-status-svn-executable "C:/cygwin17/bin/svn.exe")
))

;; svn issues a warning ("cannot set LC_CTYPE locale") if LANG is not set.
(setenv "LANG" "C")

;;________________________________________________________________
;;    diff
;;________________________________________________________________

;; Even though C:/cygwin17/bin is in the PATH, we need to specify the
;; complete path here; It is not enough to call "diff.exe".
;; 
;; Alternatively, add Cygwin17/bin to the windows-wide path
;; (Control Panel \ System \ Advanced)
(cond (on_windows_nt
       (setq ediff-diff-program "C:/cygwin17/bin/diff.exe")
))

;;________________________________________________________________
;;    Ask Cygwin to accept the windows directory separator quietly
;;________________________________________________________________
;; If we don't, emacs's ediff will be confused by the message
;;     cygwin warning:
;;       MS-DOS style path detected: C:\\Documents and Settings\\ghali\\...
;;       Preferred POSIX equivalent is: /cygdrive/c/Documents and Settings/ghali/...
;;       CYGWIN environment variable option "nodosfilewarning" turns off this warning.
;;       Consult the user's guide for more details about POSIX paths:
;;         http://cygwin.com/cygwin-ug-net/using.html#using-pathnames

(cond (on_windows_nt
       (setenv "CYGWIN" "nodosfilewarning")
))

;;________________________________________________________________
;;    scroll-left is disabled by default; enable it.
;;________________________________________________________________
(put 'scroll-left 'disabled nil)

(put 'set-goal-column 'disabled nil)

;;________________________________________________________________
;;    Display long lines by truncating them
;;________________________________________________________________

(cond (on_windows_nt   (set-default 'truncate-lines   t) ))
(cond (on_darwin       (set-default 'truncate-lines nil) ))

;;________________________________________________________________
;;    Prevent compilation mode from truncating lines
;;________________________________________________________________

(defun my-compilation-mode-hook () 
  (setq truncate-lines nil) 
  (setq truncate-partial-width-windows nil))
(add-hook 'compilation-mode-hook 'my-compilation-mode-hook)

;;________________________________________________________________
;;    Mark user-written files (for subsequent searching)
;;________________________________________________________________

(defun mark-cpp-tex-files () "Mark C, C++, pro, and LaTeX files" (interactive)
  (dired-mark-files-regexp (concat "\\.h$\\|"
                                   "\\.c$\\|"
                                   "\\.fsh$\\|"
                                   "\\.vsh$\\|"
                                   "\\.C$\\|"
                                   "\\.hpp$\\|"
                                   "\\.ipp$\\|"
                                   "\\.cpp$\\|"
                                   "\\.pro$\\|"
                                   "\\.tex$")))

(add-hook 'dired-mode-hook
          '(lambda ()
             (define-key dired-mode-map ";" 'mark-cpp-tex-files)
             ))

;;________________________________________________________________
;; to do
;;________________________________________________________________

;; Accidentally running '!' in dired-mode under windows-nt on a
;; directory crashes emacs.

;;________________________________________________________________
;;    Show matching parenthesis
;;        show-paren-mode is both a function and a variable, but
;;        "Setting this variable directly does not take effect;
;;        either customize it (see the info node `Easy Customization')...or.."
;;________________________________________________________________

(show-paren-mode t)

;;________________________________________________________________
;;    Disable set-goal-column
;;________________________________________________________________

;; No need for this brief acronym since I never use set-goal-column. 

(global-unset-key "\C-x\C-n")

;;________________________________________________________________
;;    Unlike emacs 22, emacs 23 uses a distant Alt-key.
;;________________________________________________________________

(cond (on_darwin
       (when (>= emacs-major-version 23)
         (setq mac-option-key-is-meta nil)
         (setq mac-command-key-is-meta t)
         (setq mac-command-modifier 'meta)
         (setq mac-option-modifier nil)
         )
))

;;________________________________________________________________
;;    Highlighting - Enable hi lock globally
;;________________________________________________________________

;; Highlight entire line (use when needed).
;;(global-hl-line-mode 0)

;; hi lock is only available since Emacs 22.
(when (>= emacs-major-version 22)
  (global-hi-lock-mode 1)
  (setq hi-lock-file-patterns-policy t)
)

;;________________________________________________________________
;;    Testing whether auto-updating of dired buffers is convenient
;;________________________________________________________________

;; (setq dired-auto-revert-buffer t)
;; This is a bad idea. It makes deeply recursive directories unusable.

;;________________________________________________________________
;;    Emacs 23 cuts off M-` from OS X. Handle within emacs.
;;________________________________________________________________

(global-set-key (kbd "M-§") 'other-frame)

;;________________________________________________________________
;;    Scroll lock still needs improvement.
;;________________________________________________________________

;; (setq scroll-all-mode 't)

;;________________________________________________________________
;;    hideshow;
;;    On Windows: S-Mouse-2 hides/unhides initial comment block.
;;    On Mac:     M-x hs-toggle-hiding
;;                `C-c @ C-c'   Either hide or show the current block.
;;________________________________________________________________

(load-library "hideshow")
(add-hook 'c++-mode-hook       (lambda () (hs-minor-mode 1)) )
(add-hook 'c-mode-hook         (lambda () (hs-minor-mode 1)) )
(add-hook 'makefile-mode-hook  (lambda () (hs-minor-mode 1)) )
(add-hook 'css-mode-hook       (lambda () (hs-minor-mode 1)) )

(setq hs-minor-mode-hook  'hs-hide-initial-comment-block)

(global-set-key [M-f8] 'hs-toggle-hiding)

;;________________________________________________________________
;;    uniquify -- though using <1>, <2> also has its advantages.
;;________________________________________________________________

(require 'uniquify)
(setq uniquify-buffer-name-style 'reverse)

;;________________________________________________________________
;;    hi-lock mini-manual
;;________________________________________________________________

;; `C-x w h REGEXP <RET> FACE <RET>'    highlight-regexp
;; `C-x w r REGEXP <RET>'               unhighlight-regexp
;; `C-x w l REGEXP <RET> FACE <RET>'    highlight-lines-matching-regexp
;; `C-x w b'                            hi-lock-write-interactive-patterns
;; `C-x w i'                            hi-lock-find-patterns

;; C-x w b: hi-lock-write-interactive-patterns
;; C-x w i: hi-lock-find-patterns

;;________________________________________________________________
;;    Handle files with mixed UNIX and DOS line endings.
;;________________________________________________________________

(defun remove-dos-eol ()
  "Do not use '^M' in files containing mixed UNIX and DOS line endings."
  (interactive)
  (setq buffer-display-table (make-display-table))
  (aset buffer-display-table ?\^M []))

;;________________________________________________________________
;;    Holidays
;;________________________________________________________________
;; We need to test whether we are running emacs 23 because
;; holiday-other-holidays used to be called other-holidays.

(when (>= emacs-major-version 23)
  (setq holiday-local-holidays
	'(
	  (holiday-float 10 1 2 "Canadian Thanksgiving") ; second Monday in October
	  ))
  (setq holiday-other-holidays nil)
)

;;________________________________________________________________
;;    Entering French accents
;;________________________________________________________________

;; C-x <RET> C-\ -- set-input-method (press space to see;
;;                                    french-prefix is convenient on a qwerty keyboard)
;; C-\           -- toggle-input-method
;; C-\           -- french-prefix

;;________________________________________________________________
;;    Long lines
;;________________________________________________________________

;; Consider making longlines-mode the default for text files.
;;     longlines-auto-wrap

;;________________________________________________________________
;;    C/C++ Indentation
;;________________________________________________________________

;; C-c . <RET> STYLE <RET>    ("C-c ." is c-set-style)
;; Possible styles:
;; awk bsd cc-mode ellemtel gnu java k&r linux python stroustrup user whitesmith

(require 'cc-mode)

(setq c-basic-offset 4)                 ; Amount of basic offset used by + and - symbols in `c-offsets-alist'
(setq c-comment-only-line-offset 0)     ; Extra offset for line which contains only the start of a comment
(setq indent-tabs-mode nil)             ; Indentation can insert tabs if this is non-nil

(setq-default indent-tabs-mode nil)

(c-set-offset 'substatement-open 0)     ; The brace that opens a substatement block
(c-set-offset 'brace-list-open 0)       ; Open brace of an enum or static array list

(c-set-offset 'namespace-open 0)
(c-set-offset 'namespace-close 0)
(c-set-offset 'innamespace 0)

;; May also need:
;; (c-set-offset 'inline-open 0)
;; (c-set-offset 'case-label +))

;; Remember to use
;;     `M-a' (`c-beginning-of-statement')
;;     `M-e' (`c-end-of-statement')
;;     `C-M-a' (`c-beginning-of-defun')
;;     `C-M-e' (`c-end-of-defun')
;; rather than just
;;     M-{  backward-paragraph
;;     M-}  forward-paragraph

;; Also useful is to remember that
;;      `C-c C-w' (c-subword-mode)	toggles subword mode on and off.
;; The meaning of the following keys then changes:
;;      `M-f'          `forward-word'                `c-forward-subword'
;;      `M-b'          `backward-word'               `c-backward-subword'
;; c-subword-mode is buffer local.

;; as well as:
;;      `C-c C-<DEL>', or `C-c <DEL>' (`c-hungry-delete-backwards')(2)
;;            Delete any amount of whitespace in the backwards direction
;;  
;;      `C-c C-d', `C-c C-<DELETE>', or `C-c <DELETE>' (`c-hungry-delete-forward')
;;            Delete any amount of whitespace in the forward direction

;;________________________________________________________________
;;    SGML mode (do I still need this?)
;;________________________________________________________________

(setq sgml-basic-offset 4)

;;________________________________________________________________
;;    TeX preview
;;________________________________________________________________

(autoload 'tex-math-preview "tex-math-preview" nil t)

(add-hook 'texinfo-mode-hook
           (lambda ()
             (define-key texinfo-mode-map [f10] 'tex-math-preview)))

;;________________________________

(set-frame-parameter (selected-frame) 'alpha 100)

;;________________________________________________________________
;;    The server waits for emacsclient (launched from git, ipe, ...)
;;________________________________________________________________

(server-start)
;; Press  C-x #  when done.

;;________________________________________________________________
;;    Indent html by 4
;;________________________________________________________________

(setq sgml-basic-offset 4)

;;________________________________________________________________
;;    Choose interactively from the kill ring.
;;________________________________________________________________

(require 'browse-kill-ring)
(global-set-key (kbd "C-c C-k") 'browse-kill-ring)

;;________________________________________________________________
;;    Confirm css is an adequate mode for qml files.
;;________________________________________________________________

(setq auto-mode-alist (cons '("\\.qml\\'" . css-mode) auto-mode-alist))

;;________________________________________________________________
;;    Selective auto-fill
;;________________________________________________________________

(defun selective-auto-fill-disabling-hook ()
  "Check to see if we should disable autofill."
  (save-excursion
    (when (re-search-forward "DoNotAutoFillThisFile" 1000 t)
      (auto-fill-mode -1))))

(add-hook 'find-file-hooks 'selective-auto-fill-disabling-hook)

;;________________________________________________________________
;;    unfill paragraphs and regions
;;________________________________________________________________
;; Source:
;;     http://xahlee.org/emacs/emacs_unfill-paragraph.html

(defun unfill-paragraph ()
  "Replace newline chars in current paragraph by single spaces.
This command does the reverse of `fill-paragraph'."
  (interactive)
  (let ((fill-column 90002000))
    (fill-paragraph nil)))

(defun unfill-region (start end)
  "Replace newline chars in region by single spaces.
This command does the reverse of `fill-region'."
  (interactive "r")
  (let ((fill-column 90002000))
    (fill-region start end)))
;;________________________________________________________________
;;________________________________________________________________
;;________________________________________________________________
;;________________________________________________________________