Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
3.2 KiB

  1. ;; Copyright (C) 2015-2016, 2019 Free Software Foundation, Inc
  2. ;; Author: Rocky Bernstein <rocky@gnu.org>
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;; This program is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ;; GNU General Public License for more details.
  11. ;; You should have received a copy of the GNU General Public License
  12. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ;;; Emacs Commands to associate or attach a source buffer to a command
  14. ;;; buffer and vice versa.
  15. (eval-when-compile (require 'cl-lib)) ;For cl-remove-if-not.
  16. (require 'load-relative)
  17. (require-relative-list '("buffer/command" "buffer/source")
  18. "realgud-buffer-")
  19. (require-relative-list '("shortkey") "realgud-")
  20. (declare-function realgud-cmdbuf-add-srcbuf 'realgud-buffer-command)
  21. (declare-function realgud-cmdbuf? 'realgud-buffer-command)
  22. (declare-function realgud-srcbuf-init-or-update 'realgud-source)
  23. (declare-function realgud-short-key-mode-setup 'realgud-shortkey)
  24. (defvar realgud:attach-cmdbuf-history nil "Attach command buffer history list'.")
  25. ;;;###autoload
  26. (defun realgud:attach-source-buffer(srcbuf)
  27. "Associate a source buffer with the current command buffer"
  28. (interactive "bsource buffer: ")
  29. (unless (realgud-cmdbuf?)
  30. (error "The command only works inside a command buffer"))
  31. (unless (get-buffer-process (current-buffer))
  32. (warn "Can't find a process for command buffer %s" (current-buffer)))
  33. (let* ((cmdbuf (current-buffer))
  34. (shortkey-mode? (realgud-sget 'cmdbuf-info 'src-shortkey?)))
  35. (if (stringp srcbuf) (setq srcbuf (get-buffer srcbuf)))
  36. (realgud-cmdbuf-add-srcbuf srcbuf)
  37. (realgud-srcbuf-init-or-update srcbuf cmdbuf)
  38. (if shortkey-mode?
  39. (with-current-buffer srcbuf
  40. (realgud-short-key-mode-setup 't))
  41. )
  42. )
  43. )
  44. ;;;###autoload
  45. (defun realgud:attach-cmd-buffer(cmdbuf)
  46. "Associate a command buffer with the current source buffer"
  47. (interactive
  48. (list
  49. (completing-read "Choose a realgud command buffer: "
  50. (realgud:attach-list-command-buffers) nil t nil
  51. 'realgud:attach-cmdbuf-history nil)))
  52. (if (stringp cmdbuf) (setq cmdbuf (get-buffer cmdbuf)))
  53. (let* ((srcbuf (current-buffer))
  54. (shortkey-mode?))
  55. (with-current-buffer cmdbuf
  56. (unless (realgud-cmdbuf?)
  57. (error "The buffer is not a command buffer"))
  58. (unless (get-buffer-process (current-buffer))
  59. (warn "Can't find a process for command buffer %s" (current-buffer)))
  60. (setq shortkey-mode? (realgud-sget 'cmdbuf-info 'src-shortkey?)))
  61. (add-to-list 'realgud:attach-cmdbuf-history (buffer-name cmdbuf))
  62. (realgud-cmdbuf-add-srcbuf srcbuf)
  63. (realgud-srcbuf-init-or-update srcbuf cmdbuf)
  64. (if shortkey-mode? (realgud-short-key-mode-setup 't)))
  65. )
  66. (defun realgud:attach-list-command-buffers()
  67. (mapcar 'buffer-name (cl-remove-if-not 'realgud-cmdbuf? (buffer-list))))
  68. (provide-me "realgud-")