104498
|
1 ;;; srecode/srt.el --- argument handlers for SRT files
|
|
2
|
|
3 ;; Copyright (C) 2008, 2009 Free Software Foundation, Inc.
|
|
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
|
|
28 (require 'eieio)
|
|
29 (require 'srecode/dictionary)
|
|
30 (require 'srecode/insert)
|
|
31
|
|
32 (defvar srecode-read-variable-name-history nil
|
|
33 "History for `srecode-read-variable-name'.")
|
|
34
|
|
35 (defun srecode-read-variable-name (prompt &optional initial hist default)
|
105328
|
36 "Read in the name of a declared variable in the current SRT file.
|
104498
|
37 PROMPT is the prompt to use.
|
|
38 INITIAL is the initial string.
|
|
39 HIST is the history value, otherwise `srecode-read-variable-name-history'
|
|
40 is used.
|
|
41 DEFAULT is the default if RET is hit."
|
|
42 (let* ((newdict (srecode-create-dictionary))
|
|
43 (currfcn (semantic-current-tag))
|
|
44 )
|
|
45 (srecode-resolve-argument-list
|
|
46 (mapcar 'read
|
|
47 (semantic-tag-get-attribute currfcn :arguments))
|
|
48 newdict)
|
|
49
|
|
50 (with-slots (namehash) newdict
|
|
51 (completing-read prompt namehash nil nil initial
|
|
52 (or hist 'srecode-read-variable-name-history)
|
|
53 default))
|
|
54 ))
|
|
55
|
|
56 (defvar srecode-read-major-mode-history nil
|
|
57 "History for `srecode-read-variable-name'.")
|
|
58
|
|
59 (defun srecode-read-major-mode-name (prompt &optional initial hist default)
|
|
60 "Read in the name of a desired `major-mode'.
|
|
61 PROMPT is the prompt to use.
|
|
62 INITIAL is the initial string.
|
|
63 HIST is the history value, otherwise `srecode-read-variable-name-history'
|
|
64 is used.
|
|
65 DEFAULT is the default if RET is hit."
|
|
66 (completing-read prompt obarray
|
|
67 (lambda (s) (string-match "-mode$" (symbol-name s)))
|
|
68 nil initial (or hist 'srecode-read-major-mode-history))
|
|
69 )
|
|
70
|
|
71 (defun srecode-semantic-handle-:srt (dict)
|
|
72 "Add macros into the dictionary DICT based on the current SRT file.
|
|
73 Adds the following:
|
|
74 ESCAPE_START - This files value of escape_start
|
|
75 ESCAPE_END - This files value of escape_end
|
|
76 MODE - The mode of this buffer. If not declared yet, guess."
|
|
77 (let* ((es (semantic-find-first-tag-by-name "escape_start" (current-buffer)))
|
|
78 (ee (semantic-find-first-tag-by-name "escape_end" (current-buffer)))
|
|
79 (mode-var (semantic-find-first-tag-by-name "mode" (current-buffer)))
|
|
80 (mode (if mode-var
|
|
81 (semantic-tag-variable-default mode-var)
|
|
82 nil))
|
|
83 )
|
|
84 (srecode-dictionary-set-value dict "ESCAPE_START"
|
|
85 (if es
|
|
86 (car (semantic-tag-variable-default es))
|
|
87 "{{"))
|
|
88 (srecode-dictionary-set-value dict "ESCAPE_END"
|
|
89 (if ee
|
|
90 (car (semantic-tag-variable-default ee))
|
|
91 "}}"))
|
|
92 (when (not mode)
|
|
93 (let* ((fname (file-name-nondirectory
|
|
94 (buffer-file-name (current-buffer))))
|
|
95 )
|
|
96 (when (string-match "-\\(\\w+\\)\\.srt" fname)
|
|
97 (setq mode (concat (match-string 1 fname) "-mode")))))
|
|
98
|
|
99 (when mode
|
|
100 (srecode-dictionary-set-value dict "MAJORMODE" mode))
|
|
101
|
|
102 ))
|
|
103
|
|
104 (provide 'srecode/srt)
|
|
105
|
105377
|
106 ;; arch-tag: fb69da04-0bd6-48fe-b935-f8668420ecaf
|
104498
|
107 ;;; srecode/srt.el ends here
|