Difference between revisions of "Emacs"
Jump to navigation
Jump to search
m (agh stupid <>) |
(move point to after word in <r> elt) |
||
Line 7: | Line 7: | ||
<pre> |
<pre> |
||
(defun nxml-dix-up-to-e () |
|||
"Move point before the <e> element we're looking at." |
|||
(interactive) |
|||
⚫ | |||
(goto-char xmltok-start) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
(defun nxml-dix-restriction-copy (&optional RL) |
(defun nxml-dix-restriction-copy (&optional RL) |
||
"Make a copy of the Apertium element we're looking at, and add |
"Make a copy of the Apertium element we're looking at, and add |
||
Line 12: | Line 23: | ||
restriction." |
restriction." |
||
(interactive "P") |
(interactive "P") |
||
(nxml- |
(nxml-dix-up-to-e) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
(if (looking-at "[e>]") |
|||
⚫ | |||
(kill-sexp) (yank) (newline-and-indent) (yank) |
(kill-sexp) (yank) (newline-and-indent) (yank) |
||
(goto-char (mark t)) |
(goto-char (mark t)) |
||
(let ((dir (if RL "RL" "LR"))) |
(let ((dir (if RL "RL" "LR"))) |
||
(forward-word) (insert (concat " r=\"" dir "\""))) |
(forward-word) (insert (concat " r=\"" dir "\""))) |
||
(forward-char) (just-one-space) (delete-backward-char 1 |
(forward-char) (just-one-space) (delete-backward-char 1) |
||
(forward-word 3) |
|||
(when RL |
|||
(nxml-backward-up-element) (nxml-forward-element) (forward-word 2))) |
|||
;; whatever keys you prefer: |
;; whatever keys you prefer: |
Revision as of 23:36, 11 June 2009
Emacs has a nice xml editing mode called nXML.
I often define keyboard macros as I edit, some of these I record as functions which you can put in your .emacs, since they come in handy time and again, eg. this one for bidix:
(defun nxml-dix-up-to-e () "Move point before the <e> element we're looking at." (interactive) (nxml-token-after) (goto-char xmltok-start) (let ((tok (xmltok-start-tag-qname))) (while (not (or (equal tok "e") (equal tok "<e"))) (nxml-backward-up-element) (nxml-token-after) (setq tok (xmltok-start-tag-qname))))) (defun nxml-dix-restriction-copy (&optional RL) "Make a copy of the Apertium element we're looking at, and add an LR restriction to the copy. A prefix argument makes it an RL restriction." (interactive "P") (nxml-dix-up-to-e) (kill-sexp) (yank) (newline-and-indent) (yank) (goto-char (mark t)) (let ((dir (if RL "RL" "LR"))) (forward-word) (insert (concat " r=\"" dir "\""))) (forward-char) (just-one-space) (delete-backward-char 1) (forward-word 3) (when RL (nxml-backward-up-element) (nxml-forward-element) (forward-word 2))) ;; whatever keys you prefer: (define-key nxml-mode-map (kbd "C-c L") 'nxml-dix-restriction-copy) (define-key nxml-mode-map (kbd "C-c R") (lambda nil (interactive) "Make a copy of the Apertium element we're looking at, and add an RL restriction to the copy." (nxml-dix-restriction-copy 'RL)))
Also, if you like having all <i> elements aligned at eg. column 25, the following in your .emacs lets you do M-x align
on a region to achieve that, and also aligns <p> to 10 and <r> to 44 (for bidix):
(add-hook 'align-load-hook (lambda () (add-to-list 'align-rules-list '(nxml-dix-i-align (regexp . "\\(\\s-*\\)\\(<i.*\\)$") (modes . '(nxml-mode)) (column . 25))) (add-to-list 'align-rules-list '(nxml-dix-r-align (regexp . "\\(\\s-*\\)\\(<r>.*\\)$") (tab-stop . nil) (modes . '(nxml-mode)) (column . 44))) (add-to-list 'align-rules-list '(nxml-dix-p-align (regexp . "\\(\\s-*\\)\\(<p>.*\\)$") (modes . '(nxml-mode)) (column . 10)))))