/extras/txt2tags-mode.el

http://txt2tags.googlecode.com/ · Emacs Lisp · 731 lines · 414 code · 154 blank · 163 comment · 8 complexity · 8157a38e26a27bef2d150920d080008b MD5 · raw file

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