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.

124 lines
4.4 KiB

  1. ;; Copyright (C) 2010-2011, 2014-2015 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. ;; `rdebug' Main interface to rdebug via Emacs
  8. (require 'load-relative)
  9. (require-relative-list '("../../common/helper"
  10. "../../common/track") "realgud-")
  11. (require-relative-list '("core" "track-mode") "realgud-rdebug-")
  12. ;; This is needed, or at least the docstring part of it is needed to
  13. ;; get the customization menu to work in Emacs 25.
  14. (defgroup realgud:rdebug nil
  15. "The realgud interface to the Ruby debugger, rdebug"
  16. :group 'realgud
  17. :version "25.1")
  18. (declare-function rdebug-query-cmdline 'realgud-rdebug-core)
  19. (declare-function rdebug-parse-cmd-args 'realgud-rdebug-core)
  20. (declare-function realgud:run-debugger 'realgud:run)
  21. ;; -------------------------------------------------------------------
  22. ;; User definable variables
  23. ;;
  24. (defcustom realgud:rdebug-command-name
  25. ;;"rdebug --emacs 3"
  26. "rdebug"
  27. "File name for executing the Ruby debugger and command options.
  28. This should be an executable on your path, or an absolute file name."
  29. :type 'string
  30. :group 'realgud:rdebug)
  31. (declare-function rdebug-track-mode (bool))
  32. ;; -------------------------------------------------------------------
  33. ;; The end.
  34. ;;
  35. (defun rdebug-get-script-name (args)
  36. "Parse command line ARGS.
  37. ARGS is a list of strings containing the rdebug command name. We
  38. return a list containing the script name, and whether the
  39. annotate option was set is returned.
  40. Initially annotate should be set to nil. Argument ARGS contains
  41. a tokenized list of the command line."
  42. ;; Parse the following:
  43. ;;
  44. ;; [ruby ruby-options] rdebug rdebug-options script-name script-options
  45. (and args
  46. (let ((name nil)
  47. (annotate-p nil))
  48. ;; Strip of optional "ruby" or "ruby182" etc.
  49. (when (string-match "^ruby[0-9]*$"
  50. (file-name-sans-extension
  51. (file-name-nondirectory (car args))))
  52. (pop args)
  53. (while (and args
  54. (string-match "^-" (car args)))
  55. (if (member (car args) '("-e" "-r" "-I" "-C" "-F" "-K"))
  56. (pop args))
  57. (pop args)))
  58. ;; Remove "rdebug" from "rdebug --rdebug-options script
  59. ;; --script-options"
  60. (pop args)
  61. ;; Skip to the first non-option argument.
  62. (while (and args
  63. (not name))
  64. (let ((arg (pop args)))
  65. (cond
  66. ;; Annotation or emacs option with level number.
  67. ((or (member arg '("--annotate" "-A"))
  68. (equal arg "--emacs"))
  69. (setq annotate-p t)
  70. (pop args))
  71. ;; Combined annotation and level option.
  72. ((string-match "^--annotate=[0-9]" arg)
  73. (setq annotate-p t))
  74. ;; Options with arguments.
  75. ((member arg '("-h" "--host" "-p" "--port"
  76. "-I" "--include" "-r" "--require"))
  77. (pop args))
  78. ((string-match "^-" arg)
  79. nil)
  80. (t
  81. (setq name arg)))))
  82. (and name
  83. (list name annotate-p)))))
  84. ;;;###autoload
  85. (defun realgud:rdebug (&optional opt-cmd-line no-reset)
  86. "Invoke the rdebug Ruby debugger and start the Emacs user interface.
  87. String OPT-CMD-LINE is treated like a shell string; arguments are
  88. tokenized by `split-string-and-unquote'. The tokenized string is
  89. parsed by `trepan8-parse-cmd-args' and path elements found by that
  90. are expanded using `realgud:expand-file-name-if-exists'.
  91. Normally, command buffers are reused when the same debugger is
  92. reinvoked inside a command buffer with a similar command. If we
  93. discover that the buffer has prior command-buffer information and
  94. NO-RESET is nil, then that information which may point into other
  95. buffers and source buffers which may contain marks and fringe or
  96. marginal icons is reset. See `loc-changes-clear-buffer' to clear
  97. fringe and marginal icons.
  98. "
  99. (interactive)
  100. (realgud:run-debugger "rdebug" 'rdebug-query-cmdline
  101. 'rdebug-parse-cmd-args
  102. 'realgud:rdebug-minibuffer-history
  103. opt-cmd-line no-reset)
  104. )
  105. ;;;###autoload
  106. (defalias 'rdebug 'realgud:rdebug)
  107. (provide-me "realgud-")