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.

109 lines
4.0 KiB

  1. ;; Copyright (C) 2010, 2014, 2016 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. (eval-when-compile (require 'cl-lib)) ;For setf.
  12. ;;; Miscellaneous utility functions
  13. (require 'load-relative)
  14. (defun fn-p-to-fn?-alias (fn-sym)
  15. "FN-SYM is assumed to be a symbol which is a function. If it
  16. ends in a 'p' or '-p', that suffix is stripped; in either case, a
  17. suffix with '?' is added this name is a new alias for that
  18. function FN-SYM."
  19. (if (and (symbolp fn-sym) (functionp fn-sym))
  20. (let*
  21. ((fn-str (symbol-name fn-sym))
  22. (new-fn-str
  23. (cond
  24. ((and (> (length fn-str) 2) (equal "-p" (substring fn-str -2)))
  25. (substring fn-str 0 -2))
  26. ((and (> (length fn-str) 1) (equal "p" (substring fn-str -1)))
  27. (substring fn-str 0 -1))
  28. (t fn-str)))
  29. (new-fn-sym (intern (concat new-fn-str "?"))))
  30. (defalias new-fn-sym fn-sym))))
  31. ;; FIXME push the special casing into the debuggers themselves.
  32. (defun realgud:debugger-name-transform (debugger-name)
  33. "In some cases we need to prefix a short debugger name, like
  34. 'gdb' with 'realgud:'. This does that."
  35. (let ((debugger-name-short
  36. (file-name-sans-extension (file-name-nondirectory debugger-name))))
  37. (cond
  38. ;; ((equal debugger-name-short "gdb") "realgud:gdb")
  39. ;; ((equal debugger-name-short "jdb") "realgud:jdb")
  40. ((equal debugger-name-short "tortoise") "gub")
  41. ((or (equal debugger-name "trepan.pl")
  42. (equal debugger-name-short "trepanpl"))
  43. "realgud:trepanpl")
  44. ('t debugger-name-short))))
  45. (defun buffer-killed? (buffer)
  46. "Return t if BUFFER is killed."
  47. (not (buffer-live-p buffer)))
  48. (defmacro with-current-buffer-safe (buffer &rest body)
  49. "Check that BUFFER is not nil and has not been deleted before
  50. calling `with-current-buffer'. If it has been deleted return
  51. nil."
  52. (declare (indent 1) (debug t))
  53. `(if (or (not ,buffer) (buffer-killed? ,buffer))
  54. nil
  55. (with-current-buffer ,buffer
  56. ,@body)))
  57. ;; FIXME: prepend realgud- onto the beginning of struct-symbol
  58. (defmacro realgud-sget (struct-symbol struct-field)
  59. "Simplified access to a field of a `defstruct'
  60. variable. STRUCT-SYMBOL is a defstruct symbol name. STRUCT-FIELD
  61. is a field in that. Access (STRUCT-SYMBOL-STRUCT-FIELD STRUCT-SYMBOL)"
  62. (declare (indent 1) (debug t))
  63. `(let* ((realgud-symbol-str
  64. (concat "realgud-" (symbol-name ,struct-symbol)))
  65. (realgud-field-access
  66. (intern (concat realgud-symbol-str "-" (symbol-name, struct-field)))))
  67. (funcall realgud-field-access (eval (intern realgud-symbol-str)))))
  68. (defmacro realgud-struct-field-setter (variable-name field)
  69. "Creates an defstruct setter method for field FIELD with
  70. of defstruct variable VARIABLE-NAME. For example:
  71. (realgud-struct-field-setter \"realgud-srcbuf-info\" \"short-key?\")
  72. gives:
  73. (defun realgud-srcbuf-info-short-key?=(value)
  74. (setf (realgud-srcbuf-info-short-key? realgud-srcbuf-info) value))
  75. "
  76. (declare (indent 1) (debug t))
  77. `(defun ,(intern (concat variable-name "-" field "=")) (value)
  78. ;; FIXME: figure out how to add docstring
  79. ;; ,(concat "Sets field" ,field " of " ,variable-name " to VALUE")
  80. (if ,(intern variable-name)
  81. (setf (,(intern (concat variable-name "-" field))
  82. ,(intern variable-name)) value))
  83. ))
  84. ;; (defun realgud-struct-field (var-sym field-sym)
  85. ;; (setq var-str (symbol-name var-sym))
  86. ;; (setq field-str (symbol-name field-sym))
  87. ;; (funcall (symbol-function (intern (concat var-str "-" field-str)))
  88. ;; (eval (intern var-str))))
  89. (provide-me "realgud-")
  90. ;; Local Variables:
  91. ;; byte-compile-warnings: (not cl-functions)
  92. ;; End: