conf-buffer-management.el 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. (provide 'conf-buffer-management)
  2. (defun my/cleanup-buffer-safe ()
  3. "Perform a bunch of safe operations on the whitespace content of a buffer.
  4. Does not indent buffer, because it is used for a before-save-hook, and that
  5. might be bad."
  6. (interactive)
  7. (if (not (or (string= major-mode 'makefile-gmake-mode)
  8. (string= major-mode 'makefile-mode)))
  9. (untabify (point-min) (point-max)))
  10. (delete-trailing-whitespace)
  11. (set-buffer-file-coding-system 'utf-8))
  12. (defun my/cleanup-buffer ()
  13. "Perform a bunch of operations on the whitespace content of a buffer.
  14. Including indent-buffer, which should not be called automatically on save."
  15. (interactive)
  16. (my/cleanup-buffer-safe)
  17. (indent-region (point-min) (point-max)))
  18. (global-set-key (kbd "C-c n") 'my/cleanup-buffer)
  19. (defun my/rotate-windows ()
  20. "Rotate your windows"
  21. (interactive)
  22. (cond ((not (> (count-windows)1))
  23. (message "You can't rotate a single window!"))
  24. (t
  25. (setq i 1)
  26. (setq numWindows (count-windows))
  27. (while (< i numWindows)
  28. (let* (
  29. (w1 (elt (window-list) i))
  30. (w2 (elt (window-list) (+ (% i numWindows) 1)))
  31. (b1 (window-buffer w1))
  32. (b2 (window-buffer w2))
  33. (s1 (window-start w1))
  34. (s2 (window-start w2))
  35. )
  36. (set-window-buffer w1 b2)
  37. (set-window-buffer w2 b1)
  38. (set-window-start w1 s2)
  39. (set-window-start w2 s1)
  40. (setq i (1+ i)))))))
  41. (global-set-key (kbd "C-x w r") 'my/rotate-windows)
  42. (defun my/toggle-window-split ()
  43. (interactive)
  44. (if (= (count-windows) 2)
  45. (let* ((this-win-buffer (window-buffer))
  46. (next-win-buffer (window-buffer (next-window)))
  47. (this-win-edges (window-edges (selected-window)))
  48. (next-win-edges (window-edges (next-window)))
  49. (this-win-2nd (not (and (<= (car this-win-edges)
  50. (car next-win-edges))
  51. (<= (cadr this-win-edges)
  52. (cadr next-win-edges)))))
  53. (splitter
  54. (if (= (car this-win-edges)
  55. (car (window-edges (next-window))))
  56. 'split-window-horizontally
  57. 'split-window-vertically)))
  58. (delete-other-windows)
  59. (let ((first-win (selected-window)))
  60. (funcall splitter)
  61. (if this-win-2nd (other-window 1))
  62. (set-window-buffer (selected-window) this-win-buffer)
  63. (set-window-buffer (next-window) next-win-buffer)
  64. (select-window first-win)
  65. (if this-win-2nd (other-window 1))))))
  66. (global-set-key (kbd "C-x w t") 'my/rotate-windows)