srt.el 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. ;;; srecode/srt.el --- argument handlers for SRT files
  2. ;; Copyright (C) 2008-2012 Free Software Foundation, Inc.
  3. ;; Author: Eric M. Ludlam <eric@siege-engine.com>
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; GNU Emacs is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;;
  17. ;; Filters for SRT files, the Semantic Recoder template files.
  18. ;;; Code:
  19. (eval-when-compile (require 'cl))
  20. (require 'eieio)
  21. (require 'srecode/dictionary)
  22. (require 'srecode/insert)
  23. (defvar srecode-read-variable-name-history nil
  24. "History for `srecode-read-variable-name'.")
  25. (defun srecode-read-variable-name (prompt &optional initial hist default)
  26. "Read in the name of a declared variable in the current SRT file.
  27. PROMPT is the prompt to use.
  28. INITIAL is the initial string.
  29. HIST is the history value, otherwise `srecode-read-variable-name-history'
  30. is used.
  31. DEFAULT is the default if RET is hit."
  32. (let* ((newdict (srecode-create-dictionary))
  33. (currfcn (semantic-current-tag))
  34. )
  35. (srecode-resolve-argument-list
  36. (mapcar 'read
  37. (semantic-tag-get-attribute currfcn :arguments))
  38. newdict)
  39. (with-slots (namehash) newdict
  40. (completing-read prompt namehash nil nil initial
  41. (or hist 'srecode-read-variable-name-history)
  42. default))
  43. ))
  44. (defvar srecode-read-major-mode-history nil
  45. "History for `srecode-read-variable-name'.")
  46. (defun srecode-read-major-mode-name (prompt &optional initial hist default)
  47. "Read in the name of a desired `major-mode'.
  48. PROMPT is the prompt to use.
  49. INITIAL is the initial string.
  50. HIST is the history value, otherwise `srecode-read-variable-name-history'
  51. is used.
  52. DEFAULT is the default if RET is hit."
  53. (completing-read prompt obarray
  54. (lambda (s) (string-match "-mode$" (symbol-name s)))
  55. nil initial (or hist 'srecode-read-major-mode-history))
  56. )
  57. (defun srecode-semantic-handle-:srt (dict)
  58. "Add macros into the dictionary DICT based on the current SRT file.
  59. Adds the following:
  60. ESCAPE_START - This files value of escape_start
  61. ESCAPE_END - This files value of escape_end
  62. MODE - The mode of this buffer. If not declared yet, guess."
  63. (let* ((es (semantic-find-first-tag-by-name "escape_start" (current-buffer)))
  64. (ee (semantic-find-first-tag-by-name "escape_end" (current-buffer)))
  65. (mode-var (semantic-find-first-tag-by-name "mode" (current-buffer)))
  66. (mode (if mode-var
  67. (semantic-tag-variable-default mode-var)
  68. nil))
  69. )
  70. (srecode-dictionary-set-value dict "ESCAPE_START"
  71. (if es
  72. (car (semantic-tag-variable-default es))
  73. "{{"))
  74. (srecode-dictionary-set-value dict "ESCAPE_END"
  75. (if ee
  76. (car (semantic-tag-variable-default ee))
  77. "}}"))
  78. (when (not mode)
  79. (let* ((fname (file-name-nondirectory
  80. (buffer-file-name (current-buffer))))
  81. )
  82. (when (string-match "-\\(\\w+\\)\\.srt" fname)
  83. (setq mode (concat (match-string 1 fname) "-mode")))))
  84. (when mode
  85. (srecode-dictionary-set-value dict "MAJORMODE" mode))
  86. ))
  87. (provide 'srecode/srt)
  88. ;;; srecode/srt.el ends here