Spelling fixes.
[emacs.git] / lisp / cedet / srecode / args.el
blob73445fbf13d768f73a4ed282229db67e2bd9ed72
1 ;;; srecode/args.el --- Provide some simple template arguments
3 ;; Copyright (C) 2007-2011 Free Software Foundation, Inc.
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com>
7 ;; This file is part of GNU Emacs.
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.
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.
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/>.
22 ;;; Commentary:
24 ;; Srecode templates can accept arguments. These arguments represent
25 ;; sets of dictionary words that need to be derived. This file contains
26 ;; a set of simple arguments for srecode templates.
28 (require 'srecode/dictionary)
30 ;;; Code:
32 ;;; :blank
34 ;; Using :blank means that the template should force blank lines
35 ;; before and after the template, regardless of where the insertion
36 ;; is occurring.
37 (defun srecode-semantic-handle-:blank (dict)
38 "Add macros into the dictionary DICT specifying blank line spacing.
39 The wrapgap means make sure the first and last lines of the macro
40 do not contain any text from preceding or following text."
41 ;; This won't actually get used, but it might be nice
42 ;; to know about it.
43 (srecode-dictionary-set-value dict "BLANK" t)
46 ;;; :indent ARGUMENT HANDLING
48 ;; When a :indent argument is required, the default is to indent
49 ;; for the current major mode.
50 (defun srecode-semantic-handle-:indent (dict)
51 "Add macros into the dictionary DICT for indentation."
52 (srecode-dictionary-set-value dict "INDENT" t)
55 ;;; :region ARGUMENT HANDLING
57 ;; When a :region argument is required, provide macros that
58 ;; deal with that active region.
60 ;; Regions allow a macro to wrap the region text within the
61 ;; template bounds.
63 (defvar srecode-handle-region-when-non-active-flag nil
64 "Non-nil means do region handling w/out the region being active.")
66 (defun srecode-semantic-handle-:region (dict)
67 "Add macros into the dictionary DICT based on the current :region."
68 ;; Only enable the region section if we can clearly show that
69 ;; the user is intending to do something with the region.
70 (when (or srecode-handle-region-when-non-active-flag
71 (eq last-command 'mouse-drag-region)
72 (and transient-mark-mode mark-active))
73 ;; Show the region section
74 (srecode-dictionary-show-section dict "REGION")
75 (srecode-dictionary-set-value
76 dict "REGIONTEXT" (buffer-substring-no-properties (point) (mark)))
77 ;; Only whack the region if our template output
78 ;; is also destined for the current buffer.
79 (when (eq standard-output (current-buffer))
80 (kill-region (point) (mark))))
83 ;;; :user ARGUMENT HANDLING
85 ;; When a :user argument is required, fill the dictionary with
86 ;; information about the current Emacs user.
87 (defun srecode-semantic-handle-:user (dict)
88 "Add macros into the dictionary DICT based on the current :user."
89 (srecode-dictionary-set-value dict "AUTHOR" (user-full-name))
90 (srecode-dictionary-set-value dict "LOGIN" (user-login-name))
91 (srecode-dictionary-set-value dict "EMAIL" user-mail-address)
92 (srecode-dictionary-set-value dict "EMACSINITFILE" user-init-file)
93 (srecode-dictionary-set-value dict "UID" (user-uid))
96 ;;; :time ARGUMENT HANDLING
98 ;; When a :time argument is required, fill the dictionary with
99 ;; information about the current Emacs time.
100 (defun srecode-semantic-handle-:time (dict)
101 "Add macros into the dictionary DICT based on the current :time."
102 ;; DATE Values
103 (srecode-dictionary-set-value
104 dict "YEAR" (format-time-string "%Y" (current-time)))
105 (srecode-dictionary-set-value
106 dict "MONTHNAME" (format-time-string "%B" (current-time)))
107 (srecode-dictionary-set-value
108 dict "MONTH" (format-time-string "%m" (current-time)))
109 (srecode-dictionary-set-value
110 dict "DAY" (format-time-string "%d" (current-time)))
111 (srecode-dictionary-set-value
112 dict "WEEKDAY" (format-time-string "%a" (current-time)))
113 ;; Time Values
114 (srecode-dictionary-set-value
115 dict "HOUR" (format-time-string "%H" (current-time)))
116 (srecode-dictionary-set-value
117 dict "HOUR12" (format-time-string "%l" (current-time)))
118 (srecode-dictionary-set-value
119 dict "AMPM" (format-time-string "%p" (current-time)))
120 (srecode-dictionary-set-value
121 dict "MINUTE" (format-time-string "%M" (current-time)))
122 (srecode-dictionary-set-value
123 dict "SECOND" (format-time-string "%S" (current-time)))
124 (srecode-dictionary-set-value
125 dict "TIMEZONE" (format-time-string "%Z" (current-time)))
126 ;; Convenience pre-packed date/time
127 (srecode-dictionary-set-value
128 dict "DATE" (format-time-string "%D" (current-time)))
129 (srecode-dictionary-set-value
130 dict "TIME" (format-time-string "%X" (current-time)))
133 ;;; :file ARGUMENT HANDLING
135 ;; When a :file argument is required, fill the dictionary with
136 ;; information about the file Emacs is editing at the time of
137 ;; insertion.
138 (defun srecode-semantic-handle-:file (dict)
139 "Add macros into the dictionary DICT based on the current :file."
140 (let* ((bfn (buffer-file-name))
141 (file (file-name-nondirectory bfn))
142 (dir (file-name-directory bfn)))
143 (srecode-dictionary-set-value dict "FILENAME" file)
144 (srecode-dictionary-set-value dict "FILE" (file-name-sans-extension file))
145 (srecode-dictionary-set-value dict "EXTENSION" (file-name-extension file))
146 (srecode-dictionary-set-value dict "DIRECTORY" dir)
147 (srecode-dictionary-set-value dict "MODE" (symbol-name major-mode))
148 (srecode-dictionary-set-value
149 dict "SHORTMODE"
150 (let* ((mode-name (symbol-name major-mode))
151 (match (string-match "-mode" mode-name)))
152 (if match
153 (substring mode-name 0 match)
154 mode-name)))
155 (if (or (file-exists-p "CVS")
156 (file-exists-p "RCS"))
157 (srecode-dictionary-show-section dict "RCS")
160 ;;; :system ARGUMENT HANDLING
162 ;; When a :system argument is required, fill the dictionary with
163 ;; information about the computer Emacs is running on.
164 (defun srecode-semantic-handle-:system (dict)
165 "Add macros into the dictionary DICT based on the current :system."
166 (srecode-dictionary-set-value dict "SYSTEMCONF" system-configuration)
167 (srecode-dictionary-set-value dict "SYSTEMTYPE" system-type)
168 (srecode-dictionary-set-value dict "SYSTEMNAME" (system-name))
169 (srecode-dictionary-set-value dict "MAILHOST" (or mail-host-address
170 (system-name)))
173 ;;; :kill ARGUMENT HANDLING
175 ;; When a :kill argument is required, fill the dictionary with
176 ;; information about the current kill ring.
177 (defun srecode-semantic-handle-:kill (dict)
178 "Add macros into the dictionary DICT based on the kill ring."
179 (srecode-dictionary-set-value dict "KILL" (car kill-ring))
180 (srecode-dictionary-set-value dict "KILL2" (nth 1 kill-ring))
181 (srecode-dictionary-set-value dict "KILL3" (nth 2 kill-ring))
182 (srecode-dictionary-set-value dict "KILL4" (nth 3 kill-ring))
185 (provide 'srecode/args)
187 ;;; srecode/args.el ends here