Difference between revisions of "Emacs"

From Apertium
Jump to navigation Jump to search
m (handy function)
 
m (handy function)
Line 34: Line 34:
(nxml-dix-restriction-copy 'RL)))
(nxml-dix-restriction-copy 'RL)))
</pre>
</pre>

== See also ==
[[Emacs C style for Apertium hacking]]

[[Category: Writing dictionaries]]
[[Category: Development]]

Revision as of 17:54, 1 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-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-token-after) 			
  (let ((tok (xmltok-start-tag-qname)))
    (while (not (equal tok "e"))
      (nxml-backward-up-element)
      (nxml-token-after)
      (setq tok (xmltok-start-tag-qname))))
  (if (looking-at "[e>]")
      (nxml-backward-up-element))
  (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))

;; 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)))

See also

Emacs C style for Apertium hacking