Mercurial > emacs
comparison lisp/play/handwrite.el @ 73939:99f3f0fdefd0
(handwrite): Also process lines not ending with newline. Replace some
position-fiddling with different logic. Improve performance.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Sun, 12 Nov 2006 17:35:04 +0000 |
parents | 7033930efeb9 |
children | f7702c5f335d dbe3f29e61d6 |
comparison
equal
deleted
inserted
replaced
73938:7ee3eb5213bb | 73939:99f3f0fdefd0 |
---|---|
153 (ipage 1) | 153 (ipage 1) |
154 (nlan next-line-add-newlines) ;remember the old value | 154 (nlan next-line-add-newlines) ;remember the old value |
155 (buf-name (buffer-name) ) | 155 (buf-name (buffer-name) ) |
156 (textp) | 156 (textp) |
157 (ps-buf-name) ;name of the PostScript buffer | 157 (ps-buf-name) ;name of the PostScript buffer |
158 ) | 158 (trans-table |
159 '(("ÿ" . "264") ("á" . "207") ("à" . "210") ("â" . "211") | |
160 ("ä" . "212") ("ã" . "213") ("å" . "214") ("é" . "216") | |
161 ("è" . "217") ("ê" . "220") ("ë" . "221") ("í" . "222") | |
162 ("ì" . "223") ("î" . "224") ("ï" . "225") ("ó" . "227") | |
163 ("ò" . "230") ("ô" . "231") ("ö" . "232") ("õ" . "233") | |
164 ("ú" . "234") ("ù" . "235") ("û" . "236") ("ü" . "237") | |
165 ("ß" . "247") ("°" . "241") ("®" . "250") ("©" . "251") | |
166 ("ij" . "264") ("ç" . "215") ("§" . "244") ("ñ" . "226") | |
167 ("£" . "243"))) | |
168 (escape-table '("\\\\" "(" ")")) ; \\ comes first to not work | |
169 ; on inserted backslashes | |
170 line) | |
159 (goto-char (point-min)) ;start at beginning | 171 (goto-char (point-min)) ;start at beginning |
160 (setq handwrite-psindex (1+ handwrite-psindex)) | 172 (setq handwrite-psindex (1+ handwrite-psindex)) |
161 (setq ps-buf-name | 173 (setq ps-buf-name |
162 (format "*handwritten%d.ps*" handwrite-psindex)) | 174 (format "*handwritten%d.ps*" handwrite-psindex)) |
163 (setq next-line-add-newlines t) | 175 (setq next-line-add-newlines t) |
176 (insert "xym( )a") | 188 (insert "xym( )a") |
177 (backward-char 3) | 189 (backward-char 3) |
178 (switch-to-buffer cur-buf) | 190 (switch-to-buffer cur-buf) |
179 (goto-char (point-min)) ;start at beginning | 191 (goto-char (point-min)) ;start at beginning |
180 (save-excursion | 192 (save-excursion |
181 ;;as long as we see a newline the document is not ended. | 193 (while (not (eobp)) |
182 (while (re-search-forward "\n" nil t) | 194 (setq line (thing-at-point 'line)) |
183 (previous-line 1) | 195 (dolist (escape escape-table) |
184 (beginning-of-line) | 196 (setq line (replace-regexp-in-string escape |
185 (setq pmin (point)) | 197 (concat "\\\\" escape) line))) |
186 (search-forward "\n" nil t) | 198 (dolist (trans trans-table) |
187 (backward-char 1) | 199 (setq line (replace-regexp-in-string (car trans) |
188 (copy-region-as-kill (point) pmin) | 200 (concat "\\\\" (cdr trans)) |
189 (forward-char 1) | 201 line))) |
190 (switch-to-buffer ps-buf-name) | 202 (switch-to-buffer ps-buf-name) |
191 (yank) | 203 (insert (replace-regexp-in-string "\n" "" line)) |
192 (message "write write write...") | 204 (message "write write write...") |
193 (search-forward ")a" nil t) | |
194 (backward-char 2) | |
195 (setq lastp (point)) | |
196 (beginning-of-line) | |
197 (search-forward "(" nil t) | |
198 (while (re-search-forward "[()\\]" lastp t) | |
199 (save-excursion | |
200 (setq lastp (+ lastp 1)) | |
201 (forward-char -1) | |
202 (insert "\\"))) | |
203 (setq ps-ypos (+ ps-ypos handwrite-linespace)) | 205 (setq ps-ypos (+ ps-ypos handwrite-linespace)) |
204 (end-of-line) | 206 (end-of-line) |
205 (insert "\n") | 207 (insert "\n") |
206 (setq lcount (+ lcount 1)) | 208 (setq lcount (+ lcount 1)) |
207 (cond ( (eq lcount handwrite-numlines) | 209 (when (= lcount handwrite-numlines) |
208 (setq ipage (+ ipage 1)) | 210 (setq ipage (+ ipage 1)) |
209 (insert "0 0 m\n") | 211 (insert "0 0 m\n") |
210 (insert "showpage exec Hwsave restore\n") | 212 (insert "showpage exec Hwsave restore\n") |
211 (insert "%%Page: " (number-to-string ipage) " " | 213 (insert "%%Page: " (number-to-string ipage) " " |
212 (number-to-string ipage) "\n") | 214 (number-to-string ipage) "\n") |
213 (insert "Hwjst\n") | 215 (insert "Hwjst\n") |
214 (insert "/Hwsave save def\n") | 216 (insert "/Hwsave save def\n") |
215 (if handwrite-pagenumbering | 217 (if handwrite-pagenumbering |
216 (insert "20 30 m\nxym(page " | 218 (insert "20 30 m\nxym(page " |
217 (number-to-string ipage) ")a\n")) | 219 (number-to-string ipage) ")a\n")) |
218 (setq ps-ypos 63) | 220 (setq ps-ypos 63) |
219 (setq lcount 0) | 221 (setq lcount 0)) |
220 )) | 222 (insert "44 " (number-to-string ps-ypos) " m\n") |
221 (insert "44 "(number-to-string ps-ypos) " m\n") | |
222 (insert "xym( )a") | 223 (insert "xym( )a") |
223 (backward-char 3) | 224 (backward-char 3) |
224 (switch-to-buffer cur-buf) | 225 (switch-to-buffer cur-buf) |
226 (forward-line 1) | |
225 )) | 227 )) |
226 (switch-to-buffer ps-buf-name) | 228 (switch-to-buffer ps-buf-name) |
227 (next-line 1) | 229 (next-line 1) |
228 (insert "showpage exec Hwsave restore\n\n") | 230 (insert "showpage exec Hwsave restore\n\n") |
229 (insert "%%Pages " (number-to-string ipage) " 0\n") | 231 (insert "%%Pages " (number-to-string ipage) " 0\n") |
230 (insert "%%EOF\n") | 232 (insert "%%EOF\n") |
231 (goto-char textp) ;start where the inserted text begins | |
232 (while (search-forward "ÿ" nil t) | |
233 (replace-match "\\" nil t) (insert "264")) | |
234 (goto-char textp) | |
235 (while (search-forward "á" nil t) | |
236 (replace-match "\\" nil t) (insert "207")) | |
237 (goto-char textp) | |
238 (while (search-forward "à" nil t) | |
239 (replace-match "\\" nil t) (insert "210")) | |
240 (goto-char textp) | |
241 (while (search-forward "â" nil t) | |
242 (replace-match "\\" nil t) (insert "211")) | |
243 (goto-char textp) | |
244 (while (search-forward "ä" nil t) | |
245 (replace-match "\\" nil t) (insert "212")) | |
246 (goto-char textp) | |
247 (while (search-forward "ã" nil t) | |
248 (replace-match "\\" nil t) (insert "213")) | |
249 (goto-char textp) | |
250 (while (search-forward "å" nil t) | |
251 (replace-match "\\" nil t) (insert "214")) | |
252 (goto-char textp) | |
253 (while (search-forward "é" nil t) | |
254 (replace-match "\\" nil t) (insert "216")) | |
255 (goto-char textp) | |
256 (while (search-forward "è" nil t) | |
257 (replace-match "\\" nil t) (insert "217")) | |
258 (goto-char textp) | |
259 (while (search-forward "ê" nil t) | |
260 (replace-match "\\" nil t) (insert "220")) | |
261 (goto-char textp) | |
262 (while (search-forward "ë" nil t) | |
263 (replace-match "\\" nil t) (insert "221")) | |
264 (goto-char textp) | |
265 (while (search-forward "í" nil t) | |
266 (replace-match "\\" nil t) (insert "222")) | |
267 (goto-char textp) | |
268 (while (search-forward "ì" nil t) | |
269 (replace-match "\\" nil t) (insert "223")) | |
270 (goto-char textp) | |
271 (while (search-forward "î" nil t) | |
272 (replace-match "\\" nil t) (insert "224")) | |
273 (goto-char textp) | |
274 (while (search-forward "ï" nil t) | |
275 (replace-match "\\" nil t) (insert "225")) | |
276 (goto-char textp) | |
277 (while (search-forward "ó" nil t) | |
278 (replace-match "\\" nil t) (insert "227")) | |
279 (goto-char textp) | |
280 (while (search-forward "ò" nil t) | |
281 (replace-match "\\" nil t) (insert "230")) | |
282 (goto-char textp) | |
283 (while (search-forward "ô" nil t) | |
284 (replace-match "\\" nil t) (insert "231")) | |
285 (goto-char textp) | |
286 (while (search-forward "ö" nil t) | |
287 (replace-match "\\" nil t) (insert "232")) | |
288 (goto-char textp) | |
289 (while (search-forward "õ" nil t) | |
290 (replace-match "\\" nil t) (insert "233")) | |
291 (goto-char textp) | |
292 (while (search-forward "ú" nil t) | |
293 (replace-match "\\" nil t) (insert "234")) | |
294 (goto-char textp) | |
295 (while (search-forward "ù" nil t) | |
296 (replace-match "\\" nil t) (insert "235")) | |
297 (goto-char textp) | |
298 (while (search-forward "û" nil t) | |
299 (replace-match "\\" nil t) (insert "236")) | |
300 (goto-char textp) | |
301 (while (search-forward "ü" nil t) | |
302 (replace-match "\\" nil t) (insert "237")) | |
303 (goto-char textp) | |
304 (while (search-forward "ß" nil t) | |
305 (replace-match "\\" nil t) (insert "247")) | |
306 (goto-char textp) | |
307 (while (search-forward "°" nil t) | |
308 (replace-match "\\" nil t) (insert "241")) | |
309 (goto-char textp) | |
310 (while (search-forward "®" nil t) | |
311 (replace-match "\\" nil t) (insert "250")) | |
312 (goto-char textp) | |
313 (while (search-forward "©" nil t) | |
314 (replace-match "\\" nil t) (insert "251")) | |
315 (goto-char textp) | |
316 (while (search-forward "ij" nil t) | |
317 (replace-match "\\" nil t) (insert "264")) | |
318 (goto-char textp) | |
319 (while (search-forward "ç" nil t) | |
320 (replace-match "\\" nil t) (insert "215")) | |
321 (goto-char textp) | |
322 (while (search-forward "§" nil t) | |
323 (replace-match "\\" nil t) (insert "244")) | |
324 (goto-char textp) | |
325 (while (search-forward "ñ" nil t) | |
326 (replace-match "\\" nil t) (insert "226")) | |
327 (goto-char textp) | |
328 (while (search-forward "£" nil t) | |
329 (replace-match "\\" nil t) (insert "243")) | |
330 ;;To avoid cumbersome code we simply ignore pagefeeds | 233 ;;To avoid cumbersome code we simply ignore pagefeeds |
331 (goto-char textp) | 234 (goto-char textp) |
332 (while (search-forward "\f" nil t) | 235 (while (search-forward "\f" nil t) |
333 (replace-match "" nil t) ) | 236 (replace-match "" nil t) ) |
334 (untabify textp (point-max)) ; this may result in strange tabs | 237 (untabify textp (point-max)) ; this may result in strange tabs |
340 (and (boundp 'printer-name) | 243 (and (boundp 'printer-name) |
341 printer-name))) | 244 printer-name))) |
342 (ps-lpr-switches | 245 (ps-lpr-switches |
343 (if (stringp ps-printer-name) | 246 (if (stringp ps-printer-name) |
344 (list (concat "-P" ps-printer-name))))) | 247 (list (concat "-P" ps-printer-name))))) |
345 (apply (or ps-print-region-function 'call-process-region) | 248 (apply (or (and (boundp 'ps-print-region-function) |
249 ps-print-region-function) | |
250 'call-process-region) | |
346 (point-min) (point-max) ps-lpr-command nil nil nil)))) | 251 (point-min) (point-max) ps-lpr-command nil nil nil)))) |
347 (message "") | 252 (message "") |
348 (bury-buffer ()) | 253 (bury-buffer ()) |
349 (switch-to-buffer cur-buf) | 254 (switch-to-buffer cur-buf) |
350 (goto-char tpoint) | 255 (goto-char tpoint) |