-;; Time-stamp: <2016-01-13 18:01:10 kmodi>
+;; Time-stamp: <2016-01-22 23:48:17 kmodi>
 
 ;; Functions related to editing text in the buffer
 ;; Contents:

  (progn
    (smart-mark-mode 1)))

;;; C-u before M-w/C-w to trim white space
;; Update the `region-extract-function' variable defined in `simple.el'
(setq region-extract-function
      (lambda (delete)
        (when (region-beginning)
          ;; `delete' is set to `'delete-only' in `delete-backward-char' and
          ;;  `delete-forward-char' functions.
          (if (eq delete 'delete-only)
              (delete-region (region-beginning) (region-end))
            ;; `delete' is set to `'delete' in `kill-region' function
            ;; `delete' is set to `nil' in `copy-region-as-kill' and
            ;;  `deactivate-mark' functions.

            ;; When doing `C-u M-w`, `C-u C-w', kill the region
            ;; - with all trailing whitespace removed
            ;; - also replace 2 or more spaces with single spaces
            (if (eq 4 (prefix-numeric-value current-prefix-arg))
                (let ((sel (filter-buffer-substring (region-beginning) (region-end) delete)))
                  (with-temp-buffer
                    (insert sel)
                    ;; Removing trailing whitespace from the whole temp buffer
                    (delete-trailing-whitespace)
                    (goto-char (point-min))
                    (while (re-search-forward "\\s-\\{2,\\}" nil :noerror)
                      (replace-match " "))
                    (buffer-string)))
              (filter-buffer-substring (region-beginning) (region-end) delete))))))

;;; Bindings
(bind-keys

;;  Mark Management
;;    Popping marks
;;    Smart Mark
;;  Tweaking `region-extract-function'
;;  Bindings
;;  Comment Commander

