PageRenderTime 37ms CodeModel.GetById 3ms app.highlight 26ms RepoModel.GetById 1ms app.codeStats 0ms

/extras/txt2tags-mode.el

http://txt2tags.googlecode.com/
Lisp | 731 lines | 414 code | 154 blank | 163 comment | 8 complexity | 8157a38e26a27bef2d150920d080008b MD5 | raw file
  1;; Author: Leslie Harlley Watter
  2
  3
  4;; HOWTO INSTALL
  5
  6;;
  7;; PT_BR  ( english users look below :D )
  8;;
  9
 10
 11;; 1) Crie/Copie este arquivo (txt2tags-mode.el) para o diretório ~/emacs/txt2tags/.
 12;; 2) Insira o seguinte código no final do seu ~/.emacs
 13;; ------
 14;; (add-to-list 'load-path "~/projetos/txt2tags/2.x/")
 15;; (setq auto-mode-alist (append (list
 16;; 	'("\\.t2t$" . t2t-mode)
 17;; 	)
 18;; 	(if (boundp 'auto-mode-alist) auto-mode-alist)
 19;; ))
 20;; (autoload  't2t-mode "txt2tags-mode" "Txt2tags Mode" t)
 21;; -----
 22;; E pronto, basta fechar e abrir novamente o emacs que ele irá carregar o txt2tags-mode automaticamente quando
 23;; um arquivo .t2t for aberto ;-)
 24
 25
 26
 27;;
 28;; EN_US
 29;;
 30
 31;; To install txt2tags-mode you just need to do a few steps:
 32;; 1) Copy this archieve (txt2tags-mode.el) to your ~/emacs/txt2tags directory. 
 33;; (If you don't have such a directory, you can create one just to organize your things)
 34;; 2) Add the following code to the end of your ~/.emacs
 35;; ------
 36;; (add-to-list 'load-path "~/projetos/txt2tags/2.x/")
 37;; (setq auto-mode-alist (append (list
 38;; 	'("\\.t2t$" . t2t-mode)
 39;; 	)
 40;; 	(if (boundp 'auto-mode-alist) auto-mode-alist)
 41;; ))
 42;; (autoload  't2t-mode "txt2tags-mode" "Txt2tags Mode" t)
 43;; -----
 44;; That's all. Close your emacs and reopen it. Emacs will parse and fontify all of .t2t files ;-)
 45
 46
 47
 48
 49;; TODO
 50
 51;; Ajustar as regexps de tabelas
 52;; Ajustar a regexp da data para pegar %%date(%c) e variantes
 53;; rewrite the entire documentation.
 54
 55
 56(defvar t2t-mode-hook nil)
 57(defvar t2t-mode-map nil
 58  "Keymap for txt2tags major mode")
 59
 60;; Now we're assigining a default keymap, if the user hasn't already defined one.
 61
 62;; (if t2t-mode-map nil
 63;;   (setq t2t-mode-map (make-keymap)))
 64
 65
 66
 67(defgroup t2t nil
 68  "txt2tags code editing commands for Emacs."
 69  :prefix "t2t-"
 70  :group 'languages)
 71
 72(defcustom t2t-program 
 73  (cond 
 74   ((file-exists-p "/usr/local/bin/txt2tags") "/usr/local/bin/txt2tags")
 75   ((file-exists-p "/usr/bin/txt2tags") "/usr/bin/txt2tags")
 76   ((file-exists-p "/bin/txt2tags") "/bin/txt2tags")
 77;;   ((file-exists-p "/home/leslie/bin/bin/txt2tags") "/home/leslie/bin/bin/txt2tags")
 78   ((file-exists-p "~/projetos/txt2tags/programa/txt2tags") "~/projetos/txt2tags/programa/txt2tags")
 79   ( t "txt2tags")
 80   )
 81  "File name of the txt2tags executable."
 82  :type 'file
 83  :group 't2t)
 84
 85(defcustom t2t-default-target "html"
 86  "Default target to txt2tags."
 87  :group 't2t)
 88
 89;;; Fontes novas criadas com base na sugestăo do kensanata do #emacs em irc.freenode.net
 90
 91;; cria o novo grupo txt2tags-faces que é filho de txt2tags
 92
 93(defgroup txt2tags-faces nil
 94  "txt2tags code editing commands for Emacs."
 95  :prefix "t2t-"
 96  :group 't2t)
 97
 98
 99;; data
100(defface t2t-date-face '((t (:foreground "yellow" :background "black"))) 
101  "Txt2Tags Date."  :group 'txt2tags-faces)
102
103;; conf area
104(defface t2t-config-face '((t (:foreground "yellow" :background "black"))) 
105  "Txt2Tags Config Area."  :group 'txt2tags-faces)
106
107;; conf area
108(defface t2t-postproc-face '((t (:foreground "medium spring green" :background "black"))) 
109  "Txt2Tags PostProc Area."  :group 'txt2tags-faces)
110
111
112;; Verbatim
113(defface t2t-verbatim-face '((t (:foreground "SpringGreen1" :background "black"))) 
114  "Txt2Tags Verbatim."  :group 'txt2tags-faces)
115
116;; http + e-mails
117
118(defface t2t-internet-face '((t (:foreground "dark orchid" :background "black"))) 
119  "Txt2Tags E-mail and Http." :group 'txt2tags-faces)
120
121;; números
122
123(defface t2t-numbers-face '((t (:foreground "plum1" :background "black"))) 
124  "Txt2Tags Numbers." :group 'txt2tags-faces)
125
126;; títulos de seçőes
127(defface t2t-sections-face-5 '((t (:foreground "cyan" :background "black"))) 
128  "Txt2Tags Section Titles." :group 'txt2tags-faces)
129
130(defface t2t-sections-face-4 '((t (:foreground "cyan" :background "black"))) 
131  "Txt2Tags Section Titles." :group 'txt2tags-faces)
132
133(defface t2t-sections-face-3 '((t (:foreground "cyan" :background "black"))) 
134  "Txt2Tags Section Titles." :group 'txt2tags-faces)
135
136(defface t2t-sections-face-2 '((t (:foreground "cyan" :background "black"))) 
137  "Txt2Tags Section Titles." :group 'txt2tags-faces)
138
139(defface t2t-sections-face-1 '((t (:foreground "cyan" :background "black"))) 
140  "Txt2Tags Section Titles." :group 'txt2tags-faces)
141
142
143;; Comentários yellow4
144(defface t2t-comments-face '((t (:foreground "yellow" :background "black"))) 
145  "Txt2Tags Date." :group 'txt2tags-faces)
146
147;; listas
148(defface t2t-lists-face '((t (:foreground "dodger blue" :background "black"))) 
149  "Txt2Tags Lists." :group 'txt2tags-faces)
150
151;; quote
152(defface t2t-quote-face '((t (:foreground "black" :background "yellow3"))) 
153  "Txt2Tags Quote." :group 'txt2tags-faces)
154
155;; raw
156(defface t2t-raw-face '((t (:foreground "spring green" :background "black"))) 
157  "Txt2Tags Raw." :group 'txt2tags-faces)
158
159;; region
160(defface t2t-region-face '((t (:foreground "green" :background "black"))) 
161  "Txt2Tags Region." :group 'txt2tags-faces)
162
163;; imagens
164(defface t2t-images-face '((t (:foreground "SlateBlue4" :background "black"))) 
165  "Txt2Tags Images." :group 'txt2tags-faces)
166
167;; negrito
168(defface t2t-bold-face '((t (:width extra-expanded :weight extra-bold :foreground "midnight blue" :background "black"))) 
169  "Txt2Tags Bold." :group 'txt2tags-faces)
170
171;; itálico
172(defface t2t-italic-face '((t (:slant italic :foreground "SlateBlue2" :background "black"))) 
173  "Txt2Tags Italic." :group 'txt2tags-faces)
174
175
176;; negrito + itálico
177(defface t2t-bold-italic-face '((t (:width extra-expanded :weight extra-bold :slant italic
178			    :underline nil :foreground "medium slate blue" :background "black"))) 
179  "Txt2Tags Bold Italic." :group 'txt2tags-faces)
180
181
182;; tabelas
183(defface t2t-tables-face '((t (:foreground "turquoise4" :background "black" :bold t))) 
184  "Txt2Tags Tables." :group 'txt2tags-faces)
185
186
187;; sublinhado
188(defface t2t-underline-face '((t (:underline t :foreground "SlateBlue2" :background "black"))) 
189  "Txt2Tags Underline." :group 'txt2tags-faces)
190
191;; linha
192(defface t2t-line-face '((t (:bold t :foreground "Blue2" :background "black"))) 
193  "Txt2Tags line face." :group 'txt2tags-faces)
194
195;; Fonte para mostrar o final de linha em branco em vermelho
196
197(defface t2t-trailing-whitespace '((t (:bold t :foreground "Red" :background "black"))) 
198  "Txt2Tags line face." :group 'txt2tags-faces)
199
200;; Here, we append a definition to auto-mode-alist.
201;; This tells emacs that when a buffer with a name ending with .t2t is opened, 
202;; then t2t-mode should be started in that buffer. Some modes leave this step to the user.
203
204(setq auto-mode-alist
205	  (append
206	   '(("\\.t2t\\'" . t2t-mode))
207	   auto-mode-alist))
208
209
210;; self comment
211;;; Atençăo !!! IMPORTANTE !!
212;; NAO esquecer a aspa simples antes do nome da fonte   '("^%%.*" . --->'<----t2t-comments-face)
213;; senăo tem que declarar uma variável com o mesmo nome da fonte
214;; Veja o comentário ao final deste modo
215
216
217
218(defconst t2t-font-lock-keywords-0
219  (list
220   ;; raw - NEW
221   '("[\"][\"]\\([^`]\\)+?[\"][\"]" . 't2t-verbatim-face)
222   ;; Negrito - Bold
223   '("[**][**][^ ][-/.,:?_  A-Za-zŕ-úŔ-Ú0-9]+?[^ ][**][**]" . 't2t-bold-face)
224   ;; Itálico - Italic
225   '("[/][/][^ ][-/.,:?_  A-Za-zŕ-úŔ-Ú0-9]+?[^ ][/][/]" . 't2t-italic-face) 
226   ;; Sublinhado - Underline
227   '("[_][_][^ ][-/.,:?_  A-Za-zŕ-úŔ-Ú0-9]+?[^ ][_][_]" . 't2t-underline-face)
228   ;; verbatim 
229   '("^``` .*$" . 't2t-verbatim-face)
230   '("^```$" . 't2t-verbatim-face)
231   ;; preformatado - prefformated  - verbatim
232   '("``\\([^`]\\)+?``" . 't2t-verbatim-face)
233   ;; linha horizontal - horizontal line - NEW
234   '("-\\{19\\}-+" . 't2t-line-face)
235   '("_\\{19\\}_+" . 't2t-line-face)
236   '("=\\{19\\}=+" . 't2t-line-face)
237   )
238  "Minimal highlighting expressions for T2T mode")
239
240(defconst t2t-font-lock-keywords-1
241  (append t2t-font-lock-keywords-0
242  (list
243   ;; Data - Date
244   '("%%date\\((%[mMdDyY][-/: ]%[mMdDyY][-/: ]%[mMdDyY])\\)?" . 't2t-date-face)
245   '("%%date\\((%[mMdDyY][-/: ]%[mMdDyY])\\)" . 't2t-date-face)
246   '("%%date[()%aAbBcdHImMdpSxXyY]+?" . 't2t-date-face)
247   ;; Área de Configuraçăo - Configuration area
248   ;; casa %!target 
249   '("%![-\"\<\>\'\{\}\\=;/.,:?_() A-Za-zŕ-úŔ-Ú0-9]+" . 't2t-config-face)
250   ;; Postproc Area %%!postproc
251   '("%%!postproc[-\"\<\>\'\{\}\\=;/.,:?_() A-Za-zŕ-úŔ-Ú0-9]+" . 't2t-postproc-face)
252   ;; Comentários - Comments
253   '("^%.*" . 't2t-comments-face)
254   ;; Títulos de Seçőes năo numerados - Unnumbered Section titles 
255   '("=====[-/.,:?_() A-Za-zŕ-úŔ-Ú0-9\+=]+?=====$" . 't2t-sections-face-5) 
256   '("====[-/.,:?_() A-Za-zŕ-úŔ-Ú0-9\+=]+?====$" . 't2t-sections-face-4) 
257   '("===[-/.,:?_() A-Za-zŕ-úŔ-Ú0-9\+=]+?===$" . 't2t-sections-face-3) 
258   '("==[-/.,:?_() A-Za-zŕ-úŔ-Ú0-9\+=]+?==$" . 't2t-sections-face-2) 
259   '("=[-/.,:?_() A-Za-zŕ-úŔ-Ú0-9\+]+?=$" . 't2t-sections-face-1) 
260   ;; Títulos de Seçőes năo numerados com âncora - Unnumbered Section titles with anchors
261   '("=====[-/.,:?_() A-Za-zŕ-úŔ-Ú0-9\+=]+?=====\[[-_A-Za-zŕ-úŔ-Ú0-9]+\]?$" . 't2t-sections-face-5) 
262   '("====[-/.,:?_() A-Za-zŕ-úŔ-Ú0-9\+=]+?====\[[-_A-Za-zŕ-úŔ-Ú0-9]+\]?$" . 't2t-sections-face-4) 
263   '("===[-/.,:?_() A-Za-zŕ-úŔ-Ú0-9\+=]+?===\[[-_A-Za-zŕ-úŔ-Ú0-9\]+\]?$" . 't2t-sections-face-3) 
264   '("==[-/.,:?_() A-Za-zŕ-úŔ-Ú0-9\+=]+?==\[[-_A-Za-zŕ-úŔ-Ú0-9\]+\]?$" . 't2t-sections-face-2) 
265   '("=[-/.,:?_() A-Za-zŕ-úŔ-Ú0-9]+?=\[[-_A-Za-zŕ-úŔ-Ú0-9]+\]?$" . 't2t-sections-face-1) 
266   ;; Títulos de Seçőes numerados - Numbered Section titles 
267   '("\\+\\+\\+\\+\\+[-/.,:?_() A-Za-zŕ-úŔ-Ú0-9=]+?\\+\\+\\+\\+\\+$" . 't2t-sections-face-5) 
268   '("\\+\\+\\+\\+[-/.,:?_() A-Za-zŕ-úŔ-Ú0-9=]+?\\+\\+\\+\\+$" . 't2t-sections-face-4) 
269   '("\\+\\+\\+[-/.,:?_() A-Za-zŕ-úŔ-Ú0-9=]+?\\+\\+\\+$" . 't2t-sections-face-3) 
270   '("\\+\\+[-/.,:?_() A-Za-zŕ-úŔ-Ú0-9=]+?\\+\\+$" . 't2t-sections-face-2) 
271   '("\\+[-/.,:?_() A-Za-zŕ-úŔ-Ú0-9=]+?\\+$" . 't2t-sections-face-1) 
272   ;; Títulos de Seçőes numerados com âncora- Numbered Section titles with anchors
273   '("\\+\\+\\+\\+\\+[-/.,:?_() A-Za-zŕ-úŔ-Ú0-9=]+?\\+\\+\\+\\+\\+\[[-_A-Za-zŕ-úŔ-Ú0-9]+\]?$" . 't2t-sections-face-5) 
274   '("\\+\\+\\+\\+[-/.,:?_() A-Za-zŕ-úŔ-Ú0-9=]+?\\+\\+\\+\\+\[[-_A-Za-zŕ-úŔ-Ú0-9]+\]?$" . 't2t-sections-face-4) 
275   '("\\+\\+\\+[-/.,:?_() A-Za-zŕ-úŔ-Ú0-9=]+?\\+\\+\\+\[[-_A-Za-zŕ-úŔ-Ú0-9]+\]?$" . 't2t-sections-face-3) 
276   '("\\+\\+[-/.,:?_() A-Za-zŕ-úŔ-Ú0-9=]+?\\+\\+\[[-_A-Za-zŕ-úŔ-Ú0-9]+\]?$" . 't2t-sections-face-2) 
277   '("\\+[-/.,:?_() A-Za-zŕ-úŔ-Ú0-9=]+?\\+\[[-_A-Za-zŕ-úŔ-Ú0-9]+\]?$" . 't2t-sections-face-1) 
278   ))
279  "Minimal highlighting expressions for T2T mode")
280
281
282(defconst t2t-font-lock-keywords-2
283  (append t2t-font-lock-keywords-1
284		  (list
285		   ;; image
286		   '("\\[\\([-/.,:?_A-Za-zŕ-úŔ-Ú0-9]*\\)+\\]" . 't2t-images-face)
287		   '("^ \\[\\([-/.,:?_A-Za-zŕ-úŔ-Ú0-9]*\\)+\\] $" . 't2t-images-face)
288		   ;; quote - NEW
289		   '("^\t+" . 't2t-quote-face)
290		   '("^[ \t]*-" . 't2t-lists-face)
291		   ;; colchetes - links 
292		   '("\\[\\(.*?\\)\\]" . 't2t-internet-face) 
293		   ;; páginas WEB - WEB pages
294		   '("\\(http\\|https\\|ftp\\|telnet\\)://[A-Za-z]+[.:@][A-Za-z.:/@?#]+?[A-Za-z0-9=.:~!#$/@%&*?()+-_]+" . 't2t-internet-face)
295		   '("\\(www\\|ftp\\)[0-9.]+?[A-Za-z]+[.:@][A-Za-z0-9=.:@~!#$%&/?*()+-_]+" . 't2t-internet-face)
296		   ;; e-mails 
297		   '("[A-Za-z0-9_.-]+@\\([A-Za-z0-9_-]+\.\\)+" . 't2t-internet-face)
298		   ))
299  "Additional Keywords to highlight in T2T mode")
300
301
302
303
304(defconst t2t-font-lock-keywords-3
305  (append t2t-font-lock-keywords-2
306	  (list
307	   ;; Tabela - Tables
308	   ;; linha de titulo de tabela COM e SEM os pipes
309	   ;; table title line  WITH and WITHOUT pipes
310	   '("^ ?||\\( |\\| \\|\t\\|\\sw\\|[A-Za-zŕ-úŔ-Ú0-9]\\)+" . 't2t-tables-face)
311	   ;; corpo da tabela - table body
312	   '("^|\\(\\(\\s.\\|\\sw\\| \\|[A-Za-zŕ-úŔ-Ú0-9]\\)+\\( |\\)+\\)+" . 't2t-tables-face)
313	   ;; corpo da tabela sem pipes - table body without pipes
314;;	   '("^|\\(\\(\\( \\|\t\\)\\(\\s.\\|\\sw\\| \\|[ŕ-úŔ-Ú0-9]\\)+\\)\\)+" . 't2t-tables-face)
315	   ;; Listas -- (ainda nao vi como fazer com regioes inteiras)
316	   ;; Lists
317	   '("^[ \t]+- \\b" . 't2t-lists-face )
318	   ;; definition list
319	   '("^[ \t]*: \\b" . 't2t-lists-face )
320	   ;; listas numeradas
321	   '("^[ \t]*\\+ \\b" . 't2t-lists-face )
322	   ;; numeros com cor também
323	   '(" -?[0-9.]+" . 't2t-numbers-face)
324	   )
325	  )
326  "Complete highlighting in T2T mode")
327
328
329(defconst t2t-font-lock-keywords-4
330  (append t2t-font-lock-keywords-3
331	  (list
332	   ;; regiőes !!
333	   '(txt2tags-region-lock-matcher
334	     (0 't2t-region-face) 
335	     (1 't2t-region-face))
336	   )
337	  )
338  "Regions highlighting in T2T mode")
339
340
341(defvar t2t-font-lock-keywords t2t-font-lock-keywords-4
342  "Default highlighting expressions for Txt2Tags mode")
343
344
345;; A syntax table tells Emacs how it should treat various tokens in your text for various functions,
346;; including movement within the buffer and syntax highlighting. 
347;; For example, how does Emacs know to move forward by one word (as used in the forward-word function)
348;; The syntax table gives Emacs this kind of information. 
349;; The syntax table is also used by the syntax highlighting package. 
350;; It is for this reason that we want to modify the syntax table for t2t-mode.
351
352
353;;  Original idea from font-latex-match-math-env command in font-latex.el.
354;; retirado do emacs-wiki. Enquanto eu năo tiver mais conhecimentos de lisp, fica como está
355 (defun txt2tags-region-lock-matcher (limit)
356   "
357 ```
358 This region will be highlighted
359 ```
360 " 
361  ;; search for the begin of the first region
362  (when (re-search-forward "^```$" limit t)
363    (let ((beg (match-end 0)) end ; 1st Region
364		  beg2 end2 ; 2nd Region
365		) 
366	  ;; search for end of region 1 and start of region 2
367      (if (re-search-forward "^```$" limit t)
368		  (progn
369			(setq end (match-beginning 0)
370				  beg2 (match-end 0))
371			;; search for end of region 2
372			(if (re-search-forward "^#end\n" limit t)
373				(setq end2 (- (match-beginning 0) 1))
374			  ;; no match -> length of region 2 = 0
375			  (setq end2 beg2)))
376		;; no match -> length of region 1 = 0
377        (setq end (point)))
378	  ;; save the regions
379	  (store-match-data (list beg end beg2 end2))
380      t)))
381
382
383
384(defvar t2t-mode-syntax-table nil
385  "Syntax table for t2t-mode.")
386
387(defun t2t-create-syntax-table ()
388  (if t2t-mode-syntax-table
389      ()
390    (setq t2t-mode-syntax-table (make-syntax-table))
391	
392	;; The first modification we make to the syntax table is to declare the 
393	;; underscore character '_' as being a valid part of a word. 
394	;; So now, a string like foo_bar will be treated as one word rather than two 
395	;; (the default Emacs behavior). 
396	
397	(modify-syntax-entry ?_ "w" t2t-mode-syntax-table))
398
399	;; %% inicia comentário 
400;; 	(modify-syntax-entry ?/ ". 124b" t2t-mode-syntax-table)
401;; 	(modify-syntax-entry ?* ". 23" t2t-mode-syntax-table)
402;; 	(modify-syntax-entry ?\n "> b" t2t-mode-syntax-table))
403  
404  (set-syntax-table t2t-mode-syntax-table))
405
406
407;; Here we define our entry function, give it a documentation string, make it interactive,
408;;  and call our syntax table creation function.
409
410
411
412
413;; menu
414
415;; Nota: é NECESSARIO TER O t2t-mode-map definido como năo nil para que funcione o menu
416
417(defvar t2t-mode-map () "Keymap used in t2t-mode buffers.")
418
419(when (not t2t-mode-map)
420  (setq t2t-mode-map (make-sparse-keymap))
421  (define-key t2t-mode-map [(control ?c) (control ?t) (control ?t)] 't2t-insert-normal-title)
422  (define-key t2t-mode-map [(control ?c) (control ?t) (control ?n)] 't2t-insert-numbered-title)
423  (define-key t2t-mode-map [(control ?c) (control ?f) (control ?b)] 't2t-insert-bold-face)
424  (define-key t2t-mode-map [(control ?c) (control ?f) (control ?i)] 't2t-insert-italic-face)
425  (define-key t2t-mode-map [(control ?c) (control ?f) (control ?u)] 't2t-insert-underlined-face)
426  (define-key t2t-mode-map [(control ?c) (control ?f) (control ?m)] 't2t-insert-monospace-face)
427  (define-key t2t-mode-map [(control ?c) (control ?b) (control ?c)] 't2t-insert-citation)
428  (define-key t2t-mode-map [(control ?c) (control ?b) (control ?d)] 't2t-insert-definition-list)
429  (define-key t2t-mode-map [(control ?c) (control ?b) (control ?l)] 't2t-insert-unumbered-list)
430  (define-key t2t-mode-map [(control ?c) (control ?b) (control ?n)] 't2t-insert-numbered-list)
431  (define-key t2t-mode-map [(control ?c) (control ?f) (control ?l)] 't2t-insert-formated-line)
432  (define-key t2t-mode-map [(control ?c) (control ?f) (control ?a)] 't2t-insert-formated-area)
433  (define-key t2t-mode-map [(control ?c) (control ?p) (control ?l)] 't2t-insert-protected-line)
434  (define-key t2t-mode-map [(control ?c) (control ?p) (control ?a)] 't2t-insert-protected-area)
435  (define-key t2t-mode-map [(control ?c) (control ?p) (control ?t)] 't2t-insert-protected-text)
436  (define-key t2t-mode-map [(control ?c) (control ?o) (control ?s)] 't2t-insert-separation-line)
437  (define-key t2t-mode-map [(control ?c) (control ?o) (control ?d)] 't2t-insert-emphasize-line)
438  (define-key t2t-mode-map [(control ?c) (control ?l)]              't2t-insert-link)
439  (define-key t2t-mode-map [(control ?c) (control ?i)]              't2t-insert-image)
440  (define-key t2t-mode-map [(control ?c) (control ?d)]              't2t-insert-date)
441  (define-key t2t-mode-map [(control ?c) (control ?c)]              't2t-insert-comments)
442)
443
444
445;; esse if é responsável por verificar a linguagem do sistema
446
447(if (string= (getenv "LANG") "pt_BR")
448;; ok, the user is using pt_BR language
449(easy-menu-define t2t-mode-menu t2t-mode-map
450  "'Txt2Tags-mode' menu"
451  '("T2T"
452    ("Título" 
453     ["Normal"       (t2t-insert-normal-title)      :keys "C-c C-t C-t"]
454     ["Numerado"     (t2t-insert-numbered-title)    :keys "C-c C-t C-n"]
455     )
456    ("Embelezadores"
457     ["Negrito"      (t2t-insert-bold-face)         :keys "C-c C-f C-b"]
458     ["Itálico"      (t2t-insert-italic-face)       :keys "C-c C-f C-i"]
459
460     ["Sublinhado"   (t2t-insert-underlined-face)   :keys "C-c C-f C-u"]
461     ["Monoespaçado" (t2t-insert-monospace-face)    :keys "C-c C-f C-m"]
462     ;; (progn (save-excursion (goto-char (mark)) (insert "''")) (insert "''"))
463     )
464    ("Blocos de Texto"
465     ["Citaçăo"             (t2t-insert-citation)        :keys "C-c C-b C-c"]
466     ["Lista"               (t2t-insert-unumbered-list)  :keys "C-c C-b C-l"]
467     ["Lista Numerada"      (t2t-insert-numbered-list)   :keys "C-c C-b C-n"]
468     ["Lista de Definiçăo"  (t2t-insert-definition-list) :keys "C-c C-b C-d"]
469     )
470    ("Texto Formatado"
471     ["Linha Formatada"     (t2t-insert-formated-line)   :keys "C-c C-f C-l"]
472     ["Área Formatada"      (t2t-insert-formated-area)   :keys "C-c C-f C-a"]
473     )
474    ("Texto Protegido"
475     ["Linha Protegida"     (t2t-insert-protected-line) :keys "C-c C-p C-l"]
476     ;; (progn (save-excursion (goto-char (mark)) (beginning-of-line)) (insert "\n\"\"\" ")) 
477     ["Área Protegida"      (t2t-insert-protected-area) :keys "C-c C-p C-a"]
478     ;; (progn (save-excursion (goto-char (mark)) (insert "\n\"\"\"\n")) (insert "\n\"\"\"\n")) 
479     ["Texto Protegido"     (t2t-insert-protected-text) :keys "C-c C-p C-t"]
480     ;; (progn (save-excursion (goto-char (mark)) (insert "\"\"")) (insert "\"\"")) 
481     ;;      ["Tabela" 
482     ;;       () t]
483     )
484    ("Outros"
485     ["Linha de Separaçăo"   (t2t-insert-separation-line) :keys "C-c C-o C-s"]
486     ;; (progn (save-excursion (goto-char (mark)) (beginning-of-line)) (insert "\n----------------------")) 
487     ["Linha Destacada"      (t2t-insert-emphasize-line)  :keys "C-c C-o C-d"]
488     ;; (progn (save-excursion (goto-char (mark)) (beginning-of-line)) (insert "\n======================"))
489     )
490    ("--")
491	["Links"                (t2t-insert-link)            :keys "C-c C-l"]
492	["Imagem"               (t2t-insert-image)           :keys "C-c C-i"]
493	["Data Atual"           (t2t-insert-date)            :keys "C-c C-d"]
494    ["Comentário"           (t2t-insert-comments)        :keys "C-c C-c"]
495    ;;     (progn (save-excursion (goto-char (mark)) (beginning-of-line) (insert ?% " ")))
496    )
497  )
498;; other language; try english as default
499(easy-menu-define t2t-mode-menu t2t-mode-map
500  "'Txt2Tags-mode' menu"
501  '("T2T"
502    ("Title" 
503     ["Ununmbered"       (t2t-insert-normal-title)      :keys "C-c C-t C-t"]
504     ["Numbered"     (t2t-insert-numbered-title)    :keys "C-c C-t C-n"]
505     )
506    ("Font Beautifiers"
507     ["Bold"      (t2t-insert-bold-face)         :keys "C-c C-f C-b"]
508     ["Italic"      (t2t-insert-italic-face)       :keys "C-c C-f C-i"]
509
510     ["Underline"   (t2t-insert-underlined-face)   :keys "C-c C-f C-u"]
511     ["Monospaced" (t2t-insert-monospace-face)    :keys "C-c C-f C-m"]
512     ;; (progn (save-excursion (goto-char (mark)) (insert "''")) (insert "''"))
513     )
514    ("Text Blocks"
515     ["Citation"             (t2t-insert-citation)        :keys "C-c C-b C-c"]
516     ["List"               (t2t-insert-unumbered-list)  :keys "C-c C-b C-l"]
517     ["Numbered List"      (t2t-insert-numbered-list)   :keys "C-c C-b C-n"]
518     ["Definition List"  (t2t-insert-definition-list) :keys "C-c C-b C-d"]
519     )
520    ("Verbatim"
521     ["Verbatim Line"     (t2t-insert-formated-line)   :keys "C-c C-f C-l"]
522     ["Verbatim Area"      (t2t-insert-formated-area)   :keys "C-c C-f C-a"]
523     )
524    ("RAW"
525     ["Raw line"     (t2t-insert-protected-line) :keys "C-c C-p C-l"]
526     ;; (progn (save-excursion (goto-char (mark)) (beginning-of-line)) (insert "\n\"\"\" ")) 
527     ["Raw area"      (t2t-insert-protected-area) :keys "C-c C-p C-a"]
528     ;; (progn (save-excursion (goto-char (mark)) (insert "\n\"\"\"\n")) (insert "\n\"\"\"\n")) 
529     ["RAW Text"     (t2t-insert-protected-text) :keys "C-c C-p C-t"]
530     ;; (progn (save-excursion (goto-char (mark)) (insert "\"\"")) (insert "\"\"")) 
531     ;;      ["Tabela" 
532     ;;       () t]
533     )
534    ("Others"
535     ["Horizontal Separator Line"   (t2t-insert-separation-line) :keys "C-c C-o C-s"]
536     ;; (progn (save-excursion (goto-char (mark)) (beginning-of-line)) (insert "\n----------------------")) 
537     ["Horizontal Bold Line"      (t2t-insert-emphasize-line)  :keys "C-c C-o C-d"]
538     ;; (progn (save-excursion (goto-char (mark)) (beginning-of-line)) (insert "\n======================"))
539     )
540    ("--")
541	["Links"              (t2t-insert-link)            :keys "C-c C-l"]
542	["Image"              (t2t-insert-image)           :keys "C-c C-i"]
543	["Date"               (t2t-insert-date)            :keys "C-c C-d"]
544    ["Comments"           (t2t-insert-comments)        :keys "C-c C-c"]
545    ;;     (progn (save-excursion (goto-char (mark)) (beginning-of-line) (insert ?% " ")))
546    )
547  )
548
549) ;; ends if language   
550
551
552
553
554;; titles
555
556(defun t2t-insert-normal-title ()
557  (interactive)
558  (save-excursion (goto-char (point)) (beginning-of-line)
559		  (insert "\n= "))
560  (end-of-line)
561  (insert " ="))
562
563
564(defun t2t-insert-numbered-title ()
565  (interactive)
566  (save-excursion (goto-char (point)) (beginning-of-line)
567		  (insert "\n+ "))
568  (end-of-line)
569  (insert " +"))
570
571;; faces
572
573(defun t2t-insert-bold-face ()
574  (interactive)
575  (save-excursion (goto-char (region-beginning))
576		  (insert "**"))
577  (insert "**"))
578
579
580(defun t2t-insert-italic-face ()
581  (interactive)
582  (save-excursion (goto-char (region-beginning))
583		  (insert "//"))
584  (insert "//"))
585
586
587(defun t2t-insert-underlined-face ()
588  (interactive)
589  (save-excursion (goto-char (region-beginning))
590		  (insert "__"))
591  (insert "__"))
592
593(defun t2t-insert-monospace-face ()
594  (interactive)
595  (save-excursion (goto-char (region-beginning))
596		  (insert "''"))
597  (insert "''"))
598
599;; lists
600
601(defun t2t-insert-citation ()
602  (interactive)
603  (setq citat (read-string "Texto: "))
604  (unless (equal citat "")
605  (insert (format "\n\t" citat ))))
606
607(defun t2t-insert-definition-list ()
608  (interactive)
609  (setq descr (read-string "Item: "))
610  (unless (equal descr "")
611  (insert (format "\n : %s \n" descr ))))
612
613
614(defun t2t-insert-unumbered-list ()
615  (interactive)
616  (setq unumberedlist (read-string "Item: "))
617  (unless (equal unumberedlist "")
618    (insert (format "\n - %s" unumberedlist))))
619
620
621(defun t2t-insert-numbered-list ()
622  (interactive)
623  (setq numberedlist (read-string "Item: "))
624  (unless (equal numberedlist "")
625    (insert (format "\n + %s" numberedlist))))
626
627
628;; Texto formatado
629(defun t2t-insert-formated-line ()
630  (interactive)
631  (save-excursion (goto-char (region-beginning)) (end-of-line)) (insert "\n''' "))
632
633
634(defun t2t-insert-formated-area ()
635  (interactive)
636  (save-excursion (goto-char (region-beginning)) (insert "\n'''\n")) (insert "\n'''\n"))
637
638
639
640;; texto protegido
641
642(defun t2t-insert-protected-line ()
643  (interactive)
644  (save-excursion (goto-char (region-beginning)) (beginning-of-line) (insert "\"\"\" ")))
645
646(defun t2t-insert-protected-area ()
647  (interactive)
648  (save-excursion (goto-char (region-beginning)) (insert "\n\"\"\"\n"))
649  (insert "\n\"\"\"\n"))
650
651(defun t2t-insert-protected-text ()
652  (interactive)
653  (save-excursion (goto-char (region-beginning)) (insert "\"\"")) (insert "\"\""))
654
655
656
657(defun t2t-insert-separation-line ()
658  (interactive)
659  (save-excursion 
660    (goto-line (point)) 
661    (end-of-line) 
662    (insert "\n----------------------")))
663
664
665(defun t2t-insert-emphasize-line ()
666  (interactive)
667  (save-excursion 
668    (goto-line (point)) 
669    (end-of-line) 
670    (insert "\n======================")))
671
672
673(defun t2t-insert-link ()
674  (interactive)
675  (setq linkname (read-string "Nome: "))
676  (unless (equal linkname "")
677    (setq urllink (read-string "Link: "))
678    (unless (equal urllink "")
679    (insert (format "[%s %s]" linkname urllink)))))
680
681(defun t2t-insert-image ()
682  (interactive)
683  (setq fileplusextension (read-string "Arquivo.Ext: "))
684  (unless (equal fileplusextension "")
685    (insert (format "[%s]" fileplusextension))))
686
687
688(defun t2t-insert-date ()
689  (interactive)
690  (save-excursion (goto-char (point)) (beginning-of-line) (insert ?% ?% "date\(\)")))
691
692
693(defun t2t-insert-comments ()
694  (interactive)
695  (save-excursion (goto-char (point)) (beginning-of-line) (insert ?% " ")))
696
697(defun t2t-mode ()
698  "Major mode for editing Txt2Tags files"
699  (interactive)
700  (kill-all-local-variables)
701  (t2t-create-syntax-table)
702  (make-local-variable 'font-lock-defaults)
703  (setq font-lock-defaults
704		'(t2t-font-lock-keywords))
705
706;; faz com que o final de linha seja mostrado em vermelho
707
708  (add-hook 't2t-mode-hook
709	    (lambda ()
710	      (set (make-local-variable 'show-trailing-whitespace)
711			   t )))
712
713;; Muda a variável compile-command para txt2tags arquivo.t2t
714  (add-hook 't2t-mode-hook
715	    (lambda ()
716	      (set (make-local-variable 'compile-command)
717		   (let ((file (file-name-nondirectory buffer-file-name)))
718		     (concat t2t-program " -t " t2t-default-target " " file)))))
719  
720;; Ativa por padrăo o syntax higlight
721  (add-hook 't2t-mode-hook 'turn-on-font-lock)
722;; ativa o mapa e menu
723  (use-local-map t2t-mode-map)
724  (easy-menu-add t2t-mode-menu)
725;; major-mode
726  (setq major-mode 't2t-mode)
727  (setq mode-name "T2T")
728  (run-hooks 't2t-mode-hook))
729
730(provide 't2t-mode)
731