Skip to content

Instantly share code, notes, and snippets.

@calas
Created May 12, 2010 21:23
Show Gist options
  • Save calas/399144 to your computer and use it in GitHub Desktop.
Save calas/399144 to your computer and use it in GitHub Desktop.
(defun insert-file-path (file)
"Insert path to file"
(interactive "FPath: ")
(insert (expand-file-name file)))
(global-set-key (kbd "C-c f") 'insert-file-path)
;;
(defun comment-or-uncomment-current-line-or-region ()
"Comments or uncomments current current line or whole lines in region."
(interactive)
(save-excursion
(let (min max)
(if (and transient-mark-mode mark-active)
(setq min (region-beginning) max (region-end))
(setq min (point) max (point)))
(comment-or-uncomment-region
(progn (goto-char min) (line-beginning-position))
(progn (goto-char max) (line-end-position))))))
(global-set-key (kbd "C-7") 'comment-or-uncomment-current-line-or-region)
;;
(defun popup-yank-menu()
"Popup the yank-menu with the kill-ring history"
(interactive)
(popup-menu 'yank-menu))
(global-set-key (kbd "C-c y") 'popup-yank-menu)
;; http://blog.tuxicity.se/elisp/emacs/2010/05/07/clean-up-buffer-or-region-in-emacs.html
(defun clean-up-buffer-or-region ()
"Untabifies, indents and deletes trailing whitespace from buffer or region."
(interactive)
(save-excursion
(unless (region-active-p)
(mark-whole-buffer))
(untabify (region-beginning) (region-end))
(indent-region (region-beginning) (region-end))
(save-restriction
(narrow-to-region (region-beginning) (region-end))
(delete-trailing-whitespace))))
(global-set-key (kbd "C-c n") 'clean-up-buffer-or-region)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment