;;;;
;;;;;; Normal editing
;;;;

;; would be org-mode but that's messy
(setq default-major-mode 'text-mode)
;(add-hook 'text-mode-hook 'turn-on-auto-fill)

(add-hook 'nxml-mode-hook '(lambda () (define-key nxml-mode-map (kbd "C-c C-c") 'comment-or-uncomment-region)))

;; prefer spaces to tabs
(setq-default indent-tabs-mode nil)

;; people seem to have this universally set, even though it's wrong
(setq-default tab-width 4)

;; require eol at eof
(setq require-final-newline t)

;; fill paragraphs with a single space after period
(setq sentence-end-double-space nil)

;; show bad whitespace
(setq whitespace-style '(face tabs trailing space-before-tab indentation tab-mark))

;; prefer hippie expand to dabbrev
(global-set-key [remap dabbrev-expand] 'hippie-expand)

;; abbreviations (auto-correction-ish)
(setq abbrev-file-name (locate-user-emacs-file "var/abbrevs"))
(setq save-abbrevs 'silently)
(if (file-exists-p abbrev-file-name) (quietly-read-abbrev-file))

;; I don't want to kill the character I'm zapping to
(load-library "misc")
(global-set-key [remap zap-to-char] 'zap-up-to-char)

;; make query-replace-regexp more available
(global-set-key (kbd "C-%") 'query-replace)
(global-set-key (kbd "M-%") 'query-replace-regexp)

;; mac sets these to weird defaults
(global-set-key (kbd "<home>") 'move-beginning-of-line)
(global-set-key (kbd "<end>") 'move-end-of-line)

;; C-o opening a line where you are is almost never what I want!
(defun open-line-above (arg)
  "Open a new line before the current one.

See also `newline-and-indent'."
  (interactive "p")
  (beginning-of-line)
  (open-line arg)
  (indent-according-to-mode))
(global-set-key [remap open-line] 'open-line-above)

;; undo tree is better than normal undo
(if (fboundp 'define-globalized-minor-mode)
    (progn
      (if (require 'undo-tree nil t)
          (global-undo-tree-mode 1))
      ;; don't show anything in the mode line for undo mode
      (setq undo-tree-mode-lighter "")))

;; debian does this for me, mac does not
(autoload 'browse-kill-ring "browse-kill-ring" nil t)

;; don't auto-save or make backups
(setq auto-save-default nil
      make-backup-files nil)

(require 'ansi-color)
(defun ansi-color-filter ()
  (interactive)
  (ansi-color-filter-region (region-beginning) (region-end)))

(provide 'ew-edit)