Werkoverleg met GvN.
Taken:
Syntactic profile of Dutch (SPOD)
? Verschillen tussen gewone queries, en met geëxpandeerde nodes: queries of macro's aanpassen?
- Emacs
- ✔ Edit-functie voor het formatteren van een macrobestand
- → Werkt thuis wel, maar niet op zardoz. Andere versie van indent voor Perl?
- ✔ Edit-functie voor het formatteren van een macrobestand
;;;###autoload
(defun indent-xpath-macros ()
"Indent XPath macro's in buffer"
(interactive)
(save-excursion
(save-restriction
(widen)
(atomic-change-group
;; ^( -> ^ (
(goto-char (point-min))
(while (re-search-forward "^(" nil t)
(replace-match " ("))
;; = """ -> = ";;;";\n( _Q_Q_\n[ ]
(goto-char (point-min))
(while (re-search-forward "\\(=[ \t\n]*\\)\"\"\"" nil t)
(replace-match "\\1\";;;\";\n( _Q_Q_\n "))
;; """ -> )";;;";
(goto-char (point-min))
(while (search-forward "\"\"\"" nil t)
(replace-match ")\";;;\";"))
;; [[(][ \t]*$ -> [](] _Q_Q_
(goto-char (point-min))
(while (re-search-forward "\\([[(]\\)[ \t]*$" nil t)
(replace-match "\\1 _Q_Q_"))
;; ../ -> @@/
(goto-char (point-min))
(while (search-forward "../" nil t)
(replace-match "@@/"))
;; perl-mode: indent buffer
(perl-mode)
(unwind-protect
(indent-region (point-min) (point-max))
(fundamental-mode))
;; _Q_Q_$ ->
(goto-char (point-min))
(while (re-search-forward "[ \t]*_Q_Q_[ \t]*$" nil t)
(replace-match ""))
;; ";;;";\n(\n\n -> """\n
(goto-char (point-min))
(while (re-search-forward "\";;;\";\n[ \t]*([ \t]*\n[ \t]*\n" nil t)
(replace-match "\"\"\"\n"))
;; ";;;";\n( -> """
(goto-char (point-min))
(while (re-search-forward "\";;;\";\n[ \t]*(" nil t)
(replace-match "\"\"\""))
;; )";;;"; -> """
(goto-char (point-min))
(while (search-forward ")\";;;\";" nil t)
(replace-match "\"\"\""))
;; """[ \t]+ -> """[ ]
(goto-char (point-min))
(while (re-search-forward "\"\"\"[ \t]+" nil t)
(replace-match "\"\"\" "))
;; [^ \t\n]"""+ -> [^ \t\n][ ]"""
(goto-char (point-min))
(while (re-search-forward "\\([^ \t\n]\\)\"\"\"" nil t)
(replace-match "\\1 \"\"\""))
;; = """\n(.*)""" -> """ \1"""
(goto-char (point-min))
(while (re-search-forward "=\\([ \t]*\\)\"\"\"[ \t]*\n[ \t]*\\(.*\\)\"\"\"" nil t)
(replace-match "=\\1\"\"\" \\2\"\"\""))
;; @@/ -> ../
(goto-char (point-min))
(while (search-forward "@@/" nil t)
(replace-match "../"))
;; trim white space and remove tabs
(goto-char (point-min))
(while (re-search-forward "[ \t]+$" nil t)
(replace-match ""))
(untabify (point-min) (point-max))
;; indent volgende regel van lijst
(goto-char (point-min))
(while (re-search-forward "^\\( *[^ \n#].*, *\n\\)" nil t)
(replace-match "\\1 ")
(beginning-of-line))
;; ^4 spaties -> 8 spaties
(goto-char (point-min))
(while (re-search-forward "^ " nil t)
(replace-match " "))
;; meerder lege regels -> enkele lege regel
(goto-char (point-min))
(while (re-search-forward "\n\n\n+" nil t)
(replace-match "\n\n"))
))))
Let op: Er worden wat tekenreeksen tijdelijk vervangen door andere reeksen. Aanname is dat deze vervangende reeksen verder niet voorkomen. Als dat wel het geval is dan zitten er fouten in de macro's na een indent.
Als indent mislukt dan worden alle veranderingen ongedaan gemaakt.