I find the following to be most helpfull and thought I would share. Please share yours so we can all have a better time with the best editor around!
;; Don't let emacs add lines forever at the bottom of a file
(setq next-line-add-newlines nil)
;; Only exit emacs if I hit C-x C-c twice in a row
;; Shamelessly stolen from Erik Ogan erik_at_ogan_dot_net
(defun dont-exit-emacs-yet ()
"Call `save-buffers-kill-emacs' if run twice in a row."
(interactive)
(if (eq last-command 'dont-exit-emacs-yet)
(save-buffers-kill-emacs)
(message "Hit C-x C-c again to exit emacs.")))
(global-set-key "\C-x\C-c" 'dont-exit-emacs-yet)
;; Trim any trailing whitespaces before saving a file
(defun trim-trailing-whitespace ()
"This will trim trailing whitespace before saving a file."
(interactive)
(save-excursion
(beginning-of-buffer)
(replace-regexp "[ \t]+$" "" nil)
nil)
)
(defun toggle-trim-whitespace-on ()
"This turns on whitespace trimming"
(interactive)
;; Add the hooks
(add-hook 'write-file-hooks 'trim-trailing-whitespace))
(defun toggle-trim-whitespace-off ()
"This turns pff whitespace trimming"
(interactive)
;; Remove the hooks
(remove-hook 'write-file-hooks 'trim-trailing-whitespace))
;; On by default
(add-hook 'write-file-hooks 'trim-trailing-whitespace)
;; Don't let emacs add lines forever at the bottom of a file
(setq next-line-add-newlines nil)
;; Only exit emacs if I hit C-x C-c twice in a row
;; Shamelessly stolen from Erik Ogan erik_at_ogan_dot_net
(defun dont-exit-emacs-yet ()
"Call `save-buffers-kill-emacs' if run twice in a row."
(interactive)
(if (eq last-command 'dont-exit-emacs-yet)
(save-buffers-kill-emacs)
(message "Hit C-x C-c again to exit emacs.")))
(global-set-key "\C-x\C-c" 'dont-exit-emacs-yet)
;; Trim any trailing whitespaces before saving a file
(defun trim-trailing-whitespace ()
"This will trim trailing whitespace before saving a file."
(interactive)
(save-excursion
(beginning-of-buffer)
(replace-regexp "[ \t]+$" "" nil)
nil)
)
(defun toggle-trim-whitespace-on ()
"This turns on whitespace trimming"
(interactive)
;; Add the hooks
(add-hook 'write-file-hooks 'trim-trailing-whitespace))
(defun toggle-trim-whitespace-off ()
"This turns pff whitespace trimming"
(interactive)
;; Remove the hooks
(remove-hook 'write-file-hooks 'trim-trailing-whitespace))
;; On by default
(add-hook 'write-file-hooks 'trim-trailing-whitespace)
posted by:
|
|
Unsubscribed |
