1. Fuco
  2. .emacs.d


.emacs.d / files / defuns-buffer.el

(defun create-scratch-buffer nil
  "create a new scratch buffer to work in. (could be *scratch* - *scratchX*)"
  (let ((n 0)
    (while (progn
             (setq bufname (concat "*scratch"
                                   (if (= n 0) "" (int-to-string n))
             (setq n (1+ n))
             (get-buffer bufname)))
    (switch-to-buffer (get-buffer-create bufname))

(defun untabify-buffer ()
  (untabify (point-min) (point-max)))

(defun indent-buffer ()
  (indent-region (point-min) (point-max)))

(defun indent-defun ()
  "Indent the current defun."

(defun cleanup-buffer-safe ()
  "Perform a bunch of safe operations on the whitespace content of a buffer.
Does not indent buffer, because it is used for a before-save-hook, and that
might be bad."
  (set-buffer-file-coding-system 'utf-8))

(defun cleanup-buffer ()
  "Perform a bunch of operations on the whitespace content of a buffer.
Including indent-buffer, which should not be called automatically on save."

(defun my-create-directory-on-save ()
  (when buffer-file-name
    (let ((dir (file-name-directory buffer-file-name)))
      (when (and (not (file-exists-p dir))
                 (y-or-n-p (format "Directory %s does not exist. Create it?" dir)))
        (make-directory dir t)))))

;; Borrowed from https://gist.github.com/1415844
;; Also see http://emacsworld.blogspot.com/2011/12/moving-buffers-between-windows.html
(require 'cl)
(defun rotate-left (l)
  (append  (cdr l) (list (car l))))
(defun rotate-windows ()
  (let ((start-positions (rotate-left (mapcar 'window-start (window-list))))
  (buffers (rotate-left (mapcar 'window-buffer (window-list)))))
    (mapcar* (lambda (window  buffer pos)
         (set-window-buffer window buffer)
         (set-window-start window pos))

;; TODO: add function to hide function bodies and leave just name and
;; docstring, useful for quick overview of the package. See
;; `hs-make-overlay'