;;;;;;;;;;;;;;;; format-gismu-list.el ;;;;;;;;;;;;;;;; ;;; Format English/Lojban list, engdict.gis ;;; Robert J. Chassell ;;; 4 October 1994 ;; This file provides two functions to reformat entries in the ;; 1994 English-Lojban list, `engdict.gis' so that they fit into ;; 80 columns. ;; The `replace-vertical-bar' function replaces the vertical bar with ;; the name of the function. The vertical bar is used to save ;; space; I find the name is easier to read when spelled out. ;; The `format-english-lojban-list' function reformats the list. This ;; function formats one line by default. (This is so you can test ;; what this does.) With an argument, it formats that number of ;; lines. For the gismu list, give it an argument of 16000. ;; Formatting takes a long time. You may want to do your other ;; work on a second Emacs rather than wait. ;; See the documentation for the `format-english-lojban-list' function. ;;;;;;;;;;;;;;;; What to do ;;;;;;;;;;;;;;;; ;; Visit the `engdict.gis' file in Emacs. ;; 1. Run `untabify' on the buffer. ;; 2. Move point to the first line of the definitions (after the ;; textual description) and then evaluate the following expression: ;; (progn (make-local-variable 'backup-inhibited) (setq backup-inhibited t)) ;; 3. Evaluate ;; (auto-save-mode nil) ;; 4. Evaluate ;; (replace-vertical-bar 16000) ;; 5. Evaluate ;; (format-english-lojban-list 16000) ;; 6. Manually fix the problems that the automatic formatting missed: ;; There are five cases that lead to bad formating that need ;; fixing in the original engdict.gis file: ;; Action Location ;; 1. add a parenthesis: *against rigid | force) ;; 2. replace brackets with parentheses: *dark [in the |], ;; 3. add a parenthesis: *work | of fiction), ;; 4. change % to & (since no x1 in line): %lamp (furniture), possible ;; 5. change % to & (since no x1 in line): %mall, mall/shopping ;;; Code: (defun format-english-lojban-list (count) "Format entries in the English-Lojban list, engdict.gis. Prefix arg COUNT specifies how many lines to format at once. Default is one line. (This is so you can test what this does.) The majority of entries have an initial asterisk or percent sign and are formated like this: * [initial asterisk or percent sign] English meaning ( [a left parenthesis] [optional part of entry] explication [optional] ) [a right parenthesis] [optional] , [a comma] place structure /:/ [ [a left square bracket] [optional] comment [optional] ] [a right square bracket] [optional] /=/ gismu ( [a left parenthesis] [optional] rafsi [separated by spaces] [optional] ) [a right parenthesis] [optional] The English word at the beginning is indicated in the rest of the line by a vertical bar, `|'. This function produces following: *hazard (shallow water hazard), x1 is a shoal [shallow hazard]/reef of material x2 in body of water x3 /:/ [rapids (= ri'erjmifa, ri'ercaxno)] /=/ jmifa " (interactive "p") (let ((here (1+ (count-lines 1 (point))))) ; (replace-vertical-bar count) ; (goto-line here) (while (and (not (eobp)) (> count 0)) (beginning-of-line) (message "Formatting count now is: %d " count) (cond ((looking-at "&") (forward-char 1) (insert " ") (delete-region (progn (end-of-line) (point)) (progn (skip-chars-backward " ") (point)))) ((looking-at "\*\\|%") (forward-char 1) (insert " ") (let* ((line-end (save-excursion (end-of-line) (point))) (meaning-beginning (progn (search-forward ", x" line-end t) (forward-char -1) (point))) (comment-beginning (progn (if (search-forward "/:/" line-end t) (progn (forward-char -3) (point)) ;; else no comment string (as with `%') nil))) (gismu-beginning (progn (search-forward "/=/" line-end t) (forward-char -3) (point)))) ;; Work from end of entry towards beginning, so inserted ;; spaces do not confuse the `line-end' value. ;; Indent gismu (goto-char gismu-beginning) (insert " ") ;; Format comments, if any (if comment-beginning (progn (goto-char comment-beginning) (insert "\n") (save-restriction (narrow-to-region comment-beginning gismu-beginning) (let ((fill-column 70)) (fill-region-as-paragraph (point-min) (point-max)) (indent-rigidly (point-min) (point-max) 4))))) ;; Fill place structure and indent (goto-char meaning-beginning) (insert "\n") (save-restriction (narrow-to-region meaning-beginning (if comment-beginning comment-beginning ;; else, no comment string gismu-beginning)) (let ((fill-column 72)) (fill-region-as-paragraph (point-min) (point-max)) (indent-rigidly (point-min) (point-max) 4))) ;; Remove extra blank line (delete-char -1))) ((looking-at "@") (forward-char 1) (insert " "))) (re-search-forward "^\\(\\*\\|%\\|@\\|&\\)" nil 'move) (setq count (1- count))))) (defun replace-vertical-bar (count) "Replace the vertical bar in an entry with its meaning. Prefix arg COUNT specifies how many lines to clean up at once. Default is one line." (interactive "p") (beginning-of-line) (while (and (not (eobp)) (> count 0)) (let* ((place-structure-entry-p (if (looking-at "&") t)) (line-beginning (point)) (meaning (buffer-substring (1+ (point)) (progn (re-search-forward "[(,]" (save-excursion (end-of-line) (point)) t) (skip-chars-backward " ,(") (point)))) (width (length meaning))) ;; Work backwards so value of line-beginning remains constant. (message "Vertical bar count now is: %d " count) (end-of-line) (while (search-backward "|" line-beginning t) (progn (replace-match meaning t t)) ;; Compensate for extra space taken by spelled-out word, if any (if place-structure-entry-p (save-excursion (move-to-column 60) (delete-char (- 1 width))))) (if (not (eobp)) (forward-line 1)) (setq count (1- count))))) (defun test-bad-format (count) "Check for vertical bars in first part of entry. Prefix arg COUNT specifies how many lines to clean up at once. Default is one line." (interactive "p") (beginning-of-line) (while (and (not (eobp)) (> count 0)) (if (looking-at "\*\\|%") (let ((end-of-part (re-search-forward "[(,]" (save-excursion (end-of-line) (point)) 'move))) (beginning-of-line) (if (search-forward "|" end-of-part t) (error "Found extraneous vertical bar!")))) (forward-line 1) (setq count (1- count)))) ;; for old, 1993, version of gismu list (defun clean-up-gismu-list (count) "Clean up an entry in the gismu list so it fits into 80 columns. Prefix arg COUNT specifies how many lines to clean up at once. Default is one line. (This is so you can test what this does.) When it can, `clean-up-gismu-list' folds lines at appropriate words or at semi-colons. Run `untabify' on the buffer first." (interactive "p") (while (> count 0) ;; Lojban word followed by type (move-to-column 10) (let ((here (point))) (delete-region here (progn (re-search-backward "\\w+" nil t) (forward-char 1) (point)))) (insert-char ? (- 9 (current-column))) ;; Keyword or phrase (re-search-forward "\\( \\)\\(\\w+\\|&\\)") (goto-char (match-beginning 2)) (let ((here (point))) (delete-region here (progn (re-search-backward "\\(\\w+\\|\*\\)" nil t) (forward-char 1) (point)))) (insert-char ? (- 14 (current-column))) ;; Long description (re-search-forward "\\( \\)\\(\\w+\\)") (goto-char (match-beginning 2)) (let ((here (point))) (delete-region here (progn (re-search-backward "\\(\\w+\\|\*\\)" nil t) (forward-char 1) (point)))) (if (> (current-column) 29) (insert " ") (insert-char ? (- 30 (current-column)))) ;; Other white space (while (re-search-forward "\\( [ ]*\\)\\(\\w+\\|\|--\\)" (save-excursion (end-of-line) (point)) t) (progn (goto-char (match-beginning 1)) (insert ? ) (delete-region (match-beginning 1) (match-end 1)))) ;; Fold long lines at special words: (beginning-of-line) (if (re-search-forward "\\(connective:\\|terminator:\\|sumti:\\|modifier:\\)" (save-excursion (end-of-line) (point)) t) (insert "\n ")) ;; Fold long lines at semi-colon (beginning-of-line) (while (search-forward ";" (save-excursion (end-of-line) (point)) t) (insert "\n ") (forward-line -1) (end-of-line) (while (> (current-column) 78) (progn (move-to-column 72) (forward-word -1) (insert "\n ") (end-of-line))) (forward-line 1)) ;; Fold remaining long lines (end-of-line) (while (> (current-column) 78) (progn (move-to-column 72) (forward-word -1) (if (looking-at-backward "\(") (forward-char -1)) (insert "\n ") (end-of-line))) (forward-line 1) (setq count (1- count)))) ;;;;;;;;;;;;;;;; miscellaneous experiments ;;;;;;;;;;;;;;;; (defun fix1 () (interactive) (untabify (point-min) (point-max)) (while (< (point) (point-max)) (if (re-search-forward "attitudinal" nil t) (replace-match "attdl")) (forward-line 1)) (goto-char (point-min)) (while (< (point) (point-max)) (if (re-search-forward "discursive" nil t) (replace-match "dscrv")) (forward-line 1))) (defun fix2 () (interactive) (while (< (point) (point-max)) (fix 1))) ;;;;;;;;;;;;;;;; end format-gismu-list.el ;;;;;;;;;;;;;;;;