Usuario:ManuelGR/awb.el

De Wikilibros, la colección de libros de texto de contenido libre.
Saltar a: navegación, buscar

;; AWB: Ada Wiki Book.
;; Emacs Lisp functions for adding templates to Ada source code and to
;; external links for the wikibooks en:Programming:Ada and
;; es:Programacin en Ada.
;; 
;; Author: Manuel Gomez.
;; Known bugs: regexps for source code are very buggy
;; License: GPL

(defun awb-replace-regexp (regexp rep-string)

  (goto-char (point-min))
  (while
      (search-forward-regexp regexp nil t)
    (replace-match rep-string)
    )
)

(defun awb-put-template (keyword template)

  (awb-replace-regexp (concat "\\(^ .* +\\)" keyword "\\([ ;]\\)") (concat "\\1{{" template "|" keyword "}}\\2"))
  (awb-replace-regexp (concat "^ " keyword " ") (concat " {{" template "|" keyword "}} "))
  (awb-replace-regexp (concat "^ " keyword "$") (concat " {{" template "|" keyword "}}"))
  (awb-replace-regexp (concat "\\(^ .* \\)" keyword " *$") (concat "\\1{{" template "|" keyword "}}"))
  (awb-replace-regexp (concat "\\(^ *\\)" keyword ";") (concat "\\1{{" template "|" keyword "}};"))
)

(defvar awb-ada-keyword
  '("abort"   "else"        "new"         "return"      
           "abs"      "elsif"       "not"         "reverse"     
           "abstract"         "end"         "null"                
           "accept"   "entry"               "select"      
           "access"   "exception"   "of"  "separate"    
           "aliased"  "exit"        "or"  "subtype"     
           "all"              "others"              
           "and"      "for"         "out"         "tagged"      
           "array"    "function"            "task"        
           "at"               "package"     "terminate"   
           "generic"  "pragma"      "then"        
           "begin"    "goto"        "private"     "type"        
           "body"             "procedure"           
           "if"       "protected"   "until"       
           "case"     "in"          "use"         
           "constant"         "is"  "raise"               
           "range"    "when"        
           "declare"  "limited"     "record"      "while"       
           "delay"    "loop"        "rem"         "with"        
           "delta"            "renames"             
           "digits"   "mod"         "requeue"     "xor"         
           "do")
)

(defun awb-put-kw-template (template)
  (interactive)

  (dolist (keyword awb-ada-keyword nil) (awb-put-template keyword template))
)

                
(defun awb-put-string-template ()
  (interactive)
  (awb-replace-regexp "\\( .*\\)\"\\([^\".]*\\)\"" "\\1{{Ada/\"|\\2}}"))

(defun awb-change-kw-convention ()
  (interactive)
  (awb-replace-regexp "'''\\[\\[Programming:Ada:Keywords:\\([a-z]+\\)|\\1\\]\\]'''" "{{Adakw|\\1}}")
)

(defun awb-put-comment-template ()
  (interactive)
  (awb-replace-regexp "\\( .*\\)-- *\\(.*\\)" "\\1{{Ada/--|\\2}}")
)

(defun awb-put-en-kw-template ()
  (interactive)

  (awb-put-kw-template "Adakw")
  (awb-change-kw-convention)
  )             

(defun awb-use-arm-template ()
  (interactive)

  (awb-replace-regexp "\\[http://[w\\.]*adaic.org/standards/95lrm/html/RM-\\([0-9]+\\)\.html +Section \\1: \\(.*\\)\\]" "{{Ada/RM1|\\1|\\2}}")
  (awb-replace-regexp "\\[http://[w\\.]*adaic.com/standards/95lrm/html/RM-\\([0-9]+\\)\.html +Section \\1: \\(.*\\)\\]" "{{Ada/RM1|\\1|\\2}}")

  (awb-replace-regexp "\\[http://[w\\.]*adaic.org/standards/95lrm/html/RM-\\([A-Z]+\\)\.html +Annex \\1: \\(.*\\)\\]" "{{Ada/RMA|\\1|\\2}}")
  (awb-replace-regexp "\\[http://[w\\.]*adaic.com/standards/95lrm/html/RM-\\([A-Z]+\\)\.html +Annex \\1: \\(.*\\)\\]" "{{Ada/RMA|\\1|\\2}}")

  (awb-replace-regexp "\\[http://[w\\.]*adaic.org/standards/95lrm/html/RM-\\([0-9A-Z]+\\)-\\([0-9]+\\)\.html +\\1\\.\\2 \\(.*\\)\\]" "{{Ada/RM2|\\1|\\2|\\3}}")
  (awb-replace-regexp "\\[http://[w\\.]*adaic.com/standards/95lrm/html/RM-\\([0-9A-Z]+\\)-\\([0-9]+\\)\.html +\\1\\.\\2 \\(.*\\)\\]" "{{Ada/RM2|\\1|\\2|\\3}}")

  (awb-replace-regexp "\\[http://[w\\.]*adaic.org/standards/95lrm/html/RM-\\([0-9A-Z]+\\)-\\([0-9]+\\)-\\([0-9]+\\)\.html +\\1\\.\\2\\.\\3 \\(.*\\)\\]" "{{Ada/RM3|\\1|\\2|\\3|\\4}}")
  (awb-replace-regexp "\\[http://[w\\.]*adaic.com/standards/95lrm/html/RM-\\([0-9A-Z]+\\)-\\([0-9]+\\)-\\([0-9]+\\)\.html +\\1\\.\\2\\.\\3 \\(.*\\)\\]" "{{Ada/RM3|\\1|\\2|\\3|\\4}}")
)

(defun awb-en-put-templates ()
  (interactive)

  (awb-put-kw-template "Adakw")
  (awb-change-kw-convention)
; not in en.wikibooks  (awb-put-string-template)
  (awb-put-comment-template)
  (awb-use-arm-template)
)

(defun awb-es-put-templates ()
  (interactive)

  (awb-put-kw-template "Ada/Reservada")
  (awb-put-string-template)
  (awb-put-comment-template)
  (awb-use-arm-template)
)