kkk-scratch.el 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ;;; kkk-scratch.el --- Scratch Function -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2023
  3. ;; Author: <pikuinha@t60-gentoo_musl>
  4. ;; Keywords:
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; Scratch everything
  17. ;;; Code:
  18. (defgroup kkk-scratch nil
  19. "Group of scratch things."
  20. :group 'file)
  21. (defun kkk-scratch-helper-dwim (BUFFER BUFFER_BACK)
  22. "This is a helper to all to-scratch dwim functions.
  23. BUFFER is the scratch buffer to change to.
  24. BUFFER_BACK is the scratch buffer to change back to when is called again."
  25. (let ((cb (buffer-name)))
  26. (if (string= cb BUFFER)
  27. (progn
  28. (switch-to-buffer (eval BUFFER_BACK))
  29. (bury-buffer BUFFER))
  30. (progn
  31. (set BUFFER_BACK cb)
  32. (switch-to-buffer BUFFER)))))
  33. (defvar kkk-scratch--buffer-last-buffer)
  34. (defun kkk-scratch-buffer-dwim ()
  35. "Change to the scratch buffern and back."
  36. (interactive)
  37. (kkk-scratch-helper-dwim "*scratch*"
  38. 'kkk-scratch--bufer-last-buffer))
  39. (defvar kkk-scratch--vterm-last-buffer)
  40. (defun kkk-scratch-vterm-dwim ()
  41. "Change to a scratch vterm and back."
  42. (interactive)
  43. (let ((buffer_name "*vterm-scratch*")
  44. (last_buffer 'kkk-scratch--vterm-last-buffer))
  45. (if (get-buffer buffer_name)
  46. (kkk-scratch-helper-dwim buffer_name last_buffer)
  47. (progn
  48. (set last_buffer (current-buffer))
  49. (vterm buffer_name)))))
  50. (defvar kkk-scratch--eshell-last-buffer)
  51. (defun kkk-scratch-eshell-dwim ()
  52. "Change to a scratch vterm and back."
  53. (interactive)
  54. (let ((buffer_name "*eshell-scratch*")
  55. (last_buffer 'kkk-scratch--eshell-last-buffer))
  56. (if (get-buffer buffer_name)
  57. (kkk-scratch-helper-dwim buffer_name last_buffer)
  58. (progn
  59. (set last_buffer (current-buffer))
  60. (eshell)
  61. (rename-buffer buffer_name)))))
  62. ;; (defconst kkk-scratch-command-map
  63. ;; (let ((map (make-sparse-keymap)))
  64. ;; (define-key map (kbd "b") #'kkk-scratch-buffer-dwim)
  65. ;; (define-key map (kbd "x v") #'kkk-scratch-vterm-dwim)
  66. ;; (define-key map (kbd "x e") #'kkk-scratch-eshell-dwim))
  67. ;; "Keymap for scratch comands.")
  68. (provide 'kkk-scratch)
  69. ;;; kkk-scratch.el ends here