The mqreplace.el program


Mqreplace.el is an Emacs Lisp program for use with the Unix editor Emacs. It creates two new commands, "mbh-query-replace" and "mbh-query-replace-regexp", for use either independently or within the programs names.el and words.el.

Note that this program makes direct use of accented characters in the CSX encoding; unless your Web browser uses a font based on this encoding (which is vanishingly unlikely) these characters will not appear correctly. The simplest expedient is to save this file to your own disk and view it there with software that does accept a CSX-based font.



(defun mbh-query-replace (from-string to-string &optional arg)
  "Replace some occurrences of FROM-STRING with TO-STRING
in every file forming part of the Mahābhārata.
As each match is found, the user must type a character saying
what to do with it.  For directions, type \\[help-command] at that time.

Preserves case in each replacement if `case-replace' and `case-fold-search'
are non-nil and FROM-STRING has no uppercase letters.
Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
only matches surrounded by word boundaries.

To customize possible responses, change the \"bindings\" in `query-replace-map'."

  (interactive (query-replace-read-args "Mahābhārata query replace"))

  (find-file "/home/john/work/mahābhārata/text/01_ādiparvan")
  (beginning-of-buffer)
  (perform-replace from-string to-string t nil arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/02_sabhāparvan")
  (beginning-of-buffer)
  (perform-replace from-string to-string t nil arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/03_āraõyakaparvan")
  (beginning-of-buffer)
  (perform-replace from-string to-string t nil arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/04_virāņaparvan")
  (beginning-of-buffer)
  (perform-replace from-string to-string t nil arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/05_udyogaparvan")
  (beginning-of-buffer)
  (perform-replace from-string to-string t nil arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/06_bhãųmaparvan")
  (beginning-of-buffer)
  (perform-replace from-string to-string t nil arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/07_droõaparvan")
  (beginning-of-buffer)
  (perform-replace from-string to-string t nil arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/08_karõaparvan")
  (beginning-of-buffer)
  (perform-replace from-string to-string t nil arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/09_÷alyaparvan")
  (beginning-of-buffer)
  (perform-replace from-string to-string t nil arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/10_sauptikaparvan")
  (beginning-of-buffer)
  (perform-replace from-string to-string t nil arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/11_strãparvan")
  (beginning-of-buffer)
  (perform-replace from-string to-string t nil arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/12_÷āntiparvan")
  (beginning-of-buffer)
  (perform-replace from-string to-string t nil arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/13_anu÷āsanaparvan")
  (beginning-of-buffer)
  (perform-replace from-string to-string t nil arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/14_ā÷vamedhikaparvan")
  (beginning-of-buffer)
  (perform-replace from-string to-string t nil arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/15_ā÷ramavāsikaparvan")
  (beginning-of-buffer)
  (perform-replace from-string to-string t nil arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/16_mausalaparvan")
  (beginning-of-buffer)
  (perform-replace from-string to-string t nil arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/17_mahāprasthānikaparvan")
  (beginning-of-buffer)
  (perform-replace from-string to-string t nil arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/18_svargārohaõaparvan")
  (beginning-of-buffer)
  (perform-replace from-string to-string t nil arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (message "Mahābhārata query replace complete")
)


(defun mbh-query-replace-regexp (regexp to-string &optional arg)
  "Replace some things after point matching REGEXP with TO-STRING
in every file forming part of the Mahābhārata.
As each match is found, the user must type a character saying
what to do with it.  For directions, type \\[help-command] at that time.

Preserves case in each replacement if `case-replace' and `case-fold-search'
are non-nil and REGEXP has no uppercase letters.
Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
only matches surrounded by word boundaries.
In TO-STRING, `\\&' stands for whatever matched the whole of REGEXP,
and `\\=\\N' (where N is a digit) stands for
 whatever what matched the Nth `\\(...\\)' in REGEXP."

  (interactive (query-replace-read-args "Mahābhārata query replace regexp"))

  (find-file "/home/john/work/mahābhārata/text/01_ādiparvan")
  (beginning-of-buffer)
  (perform-replace regexp to-string t t arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/02_sabhāparvan")
  (beginning-of-buffer)
  (perform-replace regexp to-string t t arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/03_āraõyakaparvan")
  (beginning-of-buffer)
  (perform-replace regexp to-string t t arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/04_virāņaparvan")
  (beginning-of-buffer)
  (perform-replace regexp to-string t t arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/05_udyogaparvan")
  (beginning-of-buffer)
  (perform-replace regexp to-string t t arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/06_bhãųmaparvan")
  (beginning-of-buffer)
  (perform-replace regexp to-string t t arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/07_droõaparvan")
  (beginning-of-buffer)
  (perform-replace regexp to-string t t arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/08_karõaparvan")
  (beginning-of-buffer)
  (perform-replace regexp to-string t t arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/09_÷alyaparvan")
  (beginning-of-buffer)
  (perform-replace regexp to-string t t arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/10_sauptikaparvan")
  (beginning-of-buffer)
  (perform-replace regexp to-string t t arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/11_strãparvan")
  (beginning-of-buffer)
  (perform-replace regexp to-string t t arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/12_÷āntiparvan")
  (beginning-of-buffer)
  (perform-replace regexp to-string t t arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/13_anu÷āsanaparvan")
  (beginning-of-buffer)
  (perform-replace regexp to-string t t arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/14_ā÷vamedhikaparvan")
  (beginning-of-buffer)
  (perform-replace regexp to-string t t arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/15_ā÷ramavāsikaparvan")
  (beginning-of-buffer)
  (perform-replace regexp to-string t t arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/16_mausalaparvan")
  (beginning-of-buffer)
  (perform-replace regexp to-string t t arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/17_mahāprasthānikaparvan")
  (beginning-of-buffer)
  (perform-replace regexp to-string t t arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (find-file "/home/john/work/mahābhārata/text/18_svargārohaõaparvan")
  (beginning-of-buffer)
  (perform-replace regexp to-string t t arg)
  (or unread-command-events (message "Done"))
  (save-buffer)
  (kill-buffer (current-buffer))

  (message "Mahābhārata query replace regexp complete")
)


(global-set-key "\C-cs" 'mbh-query-replace)
(global-set-key "\C-c\C-s" 'mbh-query-replace-regexp)


Back to home page