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