A JavaScript development environment for Emacs https://indium.readthedocs.io
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.

108 lines
3.7KB

  1. ;;; indium-debugger-locals.el --- Inspect locals -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2017-2018 Nicolas Petton
  3. ;; Author: Nicolas Petton <nicolas@petton.fr>
  4. ;; This program is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ;;; Commentary:
  15. ;;
  16. ;;; Code:
  17. (require 'indium-render)
  18. (require 'indium-inspector)
  19. (declare-function indium-debugger-get-scopes-properties "indium-debugger.el")
  20. (declare-function indium-debugger-get-current-scopes "indium-debugger.el")
  21. (defun indium-debugger-locals (&optional no-pop)
  22. "Inspect the local variables in the current stack frame's scope.
  23. Unless NO-POP is non-nil, pop the locals buffer."
  24. (interactive)
  25. (let* ((buf (indium-debugger-locals-get-buffer-create))
  26. (inhibit-read-only t)
  27. (scopes (indium-debugger-get-current-scopes)))
  28. (with-current-buffer buf
  29. (erase-buffer))
  30. (indium-debugger-get-scopes-properties
  31. scopes
  32. (lambda (properties scope)
  33. (indium-debugger-locals-render-properties properties scope no-pop)))))
  34. (defun indium-debugger-locals-maybe-refresh ()
  35. "When a local inspector is open, refresh it."
  36. (interactive)
  37. (let ((buf (indium-debugger-locals-get-buffer)))
  38. (when buf
  39. (indium-debugger-locals t))))
  40. (defun indium-debugger-locals-render-properties (properties scope &optional no-pop)
  41. "Render PROPERTIES in SCOPE.
  42. Unless NO-POP in non-nil, pop the locals buffer."
  43. (let* ((buf (indium-debugger-locals-get-buffer-create))
  44. (inhibit-read-only t)
  45. (name (indium-scope-name scope))
  46. (type (indium-scope-type scope))
  47. (description (if (or (null name)
  48. (string= name "undefined"))
  49. type
  50. name)))
  51. (with-current-buffer buf
  52. (save-excursion
  53. (goto-char (point-max))
  54. (indium-render-keyword description)
  55. (insert "\n\n")
  56. (indium-inspector--insert-sorted-properties properties)))
  57. (unless no-pop
  58. (pop-to-buffer buf))))
  59. (defun indium-debugger-locals-get-buffer ()
  60. "Return the buffer to use to inspect locals."
  61. (get-buffer (indium-debugger-locals-buffer-name)))
  62. (defun indium-debugger-locals-buffer-name ()
  63. "Return the name of the buffer to use to inspect locals."
  64. "*JS Debugger Locals*")
  65. (defun indium-debugger-locals-get-buffer-create ()
  66. "Create a locals buffer unless one exists, and return it."
  67. (let ((buf (indium-debugger-locals-get-buffer)))
  68. (unless buf
  69. (setq buf (generate-new-buffer (indium-debugger-locals-buffer-name)))
  70. (indium-debugger-locals-setup-buffer buf))
  71. buf))
  72. (defun indium-debugger-locals-setup-buffer (buffer)
  73. "Setup BUFFER."
  74. (with-current-buffer buffer
  75. (indium-debugger-locals-mode)
  76. (read-only-mode)))
  77. (defvar indium-debugger-locals-mode-map
  78. (let ((map (copy-keymap indium-inspector-mode-map)))
  79. (define-key map "g" nil)
  80. (define-key map "l" nil)
  81. map))
  82. (define-derived-mode indium-debugger-locals-mode indium-inspector-mode "Locals"
  83. "Major mode for inspecting local variables in a scope-chain.
  84. \\{indium-debugger-locals-mode-map}")
  85. (provide 'indium-debugger-locals)
  86. ;;; indium-debugger-locals.el ends here