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.

101 lines
3.4 KiB

  1. ;; show expressions using tooltip
  2. ;; Author: Rocky Bernstein <rocky@gnu.org>
  3. ;; Version: 1.1
  4. ;; Keywords: internal
  5. ;; URL: http://github.com/rocky/emacs-load-relative
  6. ;; Compatibility: GNU Emacs 25.x
  7. ;; Copyright (C) 2015 Free Software Foundation, Inc
  8. ;; This program is free software: you can redistribute it and/or
  9. ;; modify it under the terms of the GNU General Public License as
  10. ;; published by the Free Software Foundation, either version 3 of the
  11. ;; License, or (at your option) any later version.
  12. ;; This program is distributed in the hope that it will be useful, but
  13. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. ;; General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with this program. If not, see
  18. ;; <http://www.gnu.org/licenses/>.
  19. (require 'tooltip)
  20. (require 'ansi-color)
  21. (require 'load-relative)
  22. (require-relative-list '("cmds" "helper" "utils") "realgud-")
  23. (require-relative-list '("buffer/command") "realgud-buffer-")
  24. (declare-function realgud:cmd-eval 'realgud-cmd)
  25. (declare-function realgud-get-cmdbuf 'realgud-helper)
  26. (declare-function realgud-cmdbuf-pat 'realgud-send)
  27. (declare-function realgud:strip 'realgud-utils)
  28. (make-variable-buffer-local
  29. (defvar realgud:process-filter-save nil
  30. "realgud saves/restores the previous process filter here"))
  31. (defun realgud:tooltip-eval (event)
  32. "Show tip for identifier or selection under the mouse.
  33. The mouse must either point at an identifier or inside a selected
  34. region for the tip window to be shown.
  35. This function must return nil if it doesn't handle EVENT."
  36. (interactive "e")
  37. (let ((process)
  38. (cmdbuf (realgud-get-cmdbuf))
  39. (process))
  40. (when (and (eventp event)
  41. cmdbuf
  42. (setq process (get-buffer-process cmdbuf))
  43. (posn-point (event-end event))
  44. )
  45. (let ((expr (tooltip-expr-to-print event)))
  46. (when expr
  47. (with-current-buffer cmdbuf
  48. (setq realgud:process-filter-save (process-filter process))
  49. (set-process-filter process 'realgud:eval-process-output))
  50. (realgud:cmd-eval expr)
  51. ))
  52. )))
  53. (defun realgud:eval-process-output (process output-str)
  54. "Process debugger output and show it in a tooltip window."
  55. (set-process-filter process
  56. (or realgud:process-filter-save 'comint-output-filter))
  57. (with-current-buffer (realgud-get-cmdbuf)
  58. (goto-char (process-mark process))
  59. (setq comint-last-input-end (process-mark process))
  60. (insert output-str)
  61. (set-marker (process-mark process) (point)))
  62. (setq comint-last-output-start
  63. (setq realgud-last-output-start (process-mark process)))
  64. (tooltip-show (realgud:eval-strip process output-str))
  65. )
  66. (defun realgud:eval-strip-default(prompt-regexp output-str)
  67. (realgud:strip
  68. (ansi-color-filter-apply
  69. (if (string-match prompt-regexp output-str)
  70. (substring output-str 0 (match-beginning 0))
  71. output-str))))
  72. (defun realgud:eval-strip(process output-str)
  73. "Return OUTPUT-STR with any prompt of PROCESS stripped from its end."
  74. (save-match-data
  75. (with-current-buffer (process-buffer process)
  76. (let* ((prompt-pat (realgud-cmdbuf-pat "prompt"))
  77. (prompt-regexp (realgud-loc-pat-regexp prompt-pat))
  78. (eval-filter (realgud-sget 'cmdbuf-info 'callback-eval-filter))
  79. )
  80. (if eval-filter
  81. (funcall eval-filter output-str)
  82. (realgud:eval-strip-default prompt-regexp output-str))
  83. ))))
  84. (provide-me "realgud-")