Mercurial > emacs
comparison lisp/textmodes/reftex-global.el @ 59736:fc3483d0f93e
* textmodes/reftex-global.el (reftex-isearch-push-state-function)
(reftex-isearch-pop-state-function, reftex-isearch-isearch-search)
(reftex-isearch-switch-to-next-file, reftex-isearch-turn-off)
(reftex-isearch-turn-on, reftex-isearch-minor-mode): New functions.
author | Carsten Dominik <dominik@science.uva.nl> |
---|---|
date | Wed, 26 Jan 2005 08:28:31 +0000 |
parents | 9bad65481674 |
children | 35f6599373fc f8a7a9ba3d08 |
comparison
equal
deleted
inserted
replaced
59735:58ae6b59e2ee | 59736:fc3483d0f93e |
---|---|
336 (ding) | 336 (ding) |
337 (or (y-or-n-p (format "Buffer %s is read-only. Continue? " | 337 (or (y-or-n-p (format "Buffer %s is read-only. Continue? " |
338 (buffer-name buf))) | 338 (buffer-name buf))) |
339 (error "Abort")))))) | 339 (error "Abort")))))) |
340 | 340 |
341 (defun reftex-isearch-wrap-function () | |
342 (if (not isearch-word) | |
343 (switch-to-buffer | |
344 (funcall isearch-next-buffer-function (current-buffer) t))) | |
345 (goto-char (if isearch-forward (point-min) (point-max)))) | |
346 | |
347 (defun reftex-isearch-push-state-function () | |
348 `(lambda (cmd) | |
349 (reftex-isearch-pop-state-function cmd ,(current-buffer)))) | |
350 | |
351 (defun reftex-isearch-pop-state-function (cmd buffer) | |
352 (switch-to-buffer buffer)) | |
353 | |
354 (defun reftex-isearch-isearch-search (string bound noerror) | |
355 (let ((nxt-buff nil) | |
356 (search-fun | |
357 (cond | |
358 (isearch-word | |
359 (if isearch-forward 'word-search-forward 'word-search-backward)) | |
360 (isearch-regexp | |
361 (if isearch-forward 're-search-forward 're-search-backward)) | |
362 (t | |
363 (if isearch-forward 'search-forward 'search-backward))))) | |
364 (or | |
365 (funcall search-fun string bound noerror) | |
366 (unless bound | |
367 (condition-case nil | |
368 (when isearch-next-buffer-function | |
369 (while (not (funcall search-fun string bound noerror)) | |
370 (cond | |
371 (isearch-forward | |
372 (setq nxt-buff | |
373 (funcall isearch-next-buffer-function | |
374 (current-buffer))) | |
375 (if (not nxt-buff) | |
376 (progn | |
377 (error "Wrap forward")) | |
378 (switch-to-buffer nxt-buff) | |
379 (goto-char (point-min)))) | |
380 (t | |
381 (setq nxt-buff | |
382 (funcall isearch-next-buffer-function | |
383 (current-buffer))) | |
384 (if (not nxt-buff) | |
385 (progn | |
386 (error "Wrap backward")) | |
387 (switch-to-buffer nxt-buff) | |
388 (goto-char (point-max)))))) | |
389 (point)) | |
390 (error nil)))))) | |
391 | |
392 ;;; This function is called when isearch reaches the end of a | |
393 ;;; buffer. For reftex what we want to do is not wrap to the | |
394 ;;; beginning, but switch to the next buffer in the logical order of | |
395 ;;; the document. This function looks through list of files in the | |
396 ;;; document (reftex-all-document-files), searches for the current | |
397 ;;; buffer and switches to the next/previous one in the logical order | |
398 ;;; of the document. If WRAPP is true then wrap the search to the | |
399 ;;; beginning/end of the file list, depending of the search direction. | |
400 (defun reftex-isearch-switch-to-next-file (crt-buf &optional wrapp) | |
401 (reftex-access-scan-info) | |
402 (let* ((cb (buffer-file-name crt-buf)) | |
403 (flist (reftex-all-document-files)) | |
404 (orig-flist flist)) | |
405 (when flist | |
406 (if wrapp | |
407 (unless isearch-forward | |
408 (setq flist (last flist))) | |
409 (unless isearch-forward | |
410 (setq flist (nreverse (copy-list flist))) | |
411 (setq orig-flist flist)) | |
412 (while (not (string= (car flist) cb)) | |
413 (setq flist (cdr flist))) | |
414 (setq flist (cdr flist))) | |
415 (when flist | |
416 (find-file (car flist)))))) | |
417 | |
418 ;;;###autoload | |
419 (defvar reftex-isearch-minor-mode nil) | |
420 (make-variable-buffer-local 'reftex-isearch-minor-mode) | |
421 | |
422 ;;;###autoload | |
423 (defun reftex-isearch-minor-mode (&optional arg) | |
424 "When on, isearch searches the whole document, not only the current file. | |
425 This minor mode allows isearch to search through all the files of | |
426 the current TeX document. | |
427 | |
428 With no argument, this command toggles | |
429 `reftex-isearch-minor-mode'. With a prefix argument ARG, turn | |
430 `reftex-isearch-minor-mode' on iff ARG is positive." | |
431 (interactive "P") | |
432 (let ((old-reftex-isearch-minor-mode reftex-isearch-minor-mode)) | |
433 (setq reftex-isearch-minor-mode | |
434 (not (or (and (null arg) reftex-isearch-minor-mode) | |
435 (<= (prefix-numeric-value arg) 0)))) | |
436 (unless (eq reftex-isearch-minor-mode old-reftex-isearch-minor-mode) | |
437 (if reftex-isearch-minor-mode | |
438 (progn | |
439 (dolist (crt-buf (buffer-list)) | |
440 (with-current-buffer crt-buf | |
441 (when reftex-mode | |
442 (set (make-local-variable 'isearch-wrap-function) | |
443 'reftex-isearch-wrap-function) | |
444 (set (make-local-variable 'isearch-search-fun-function) | |
445 (lambda () 'reftex-isearch-isearch-search)) | |
446 (set (make-local-variable 'isearch-push-state-function) | |
447 'reftex-isearch-push-state-function) | |
448 (set (make-local-variable 'isearch-next-buffer-function) | |
449 'reftex-isearch-switch-to-next-file) | |
450 (setq reftex-isearch-minor-mode t)))) | |
451 (add-hook 'reftex-mode-hook 'reftex-isearch-minor-mode)) | |
452 (dolist (crt-buf (buffer-list)) | |
453 (with-current-buffer crt-buf | |
454 (when reftex-mode | |
455 (kill-local-variable 'isearch-wrap-function) | |
456 (kill-local-variable 'isearch-search-fun-function) | |
457 (kill-local-variable 'isearch-push-state-function) | |
458 (kill-local-variable 'isearch-next-buffer-function) | |
459 (setq reftex-isearch-minor-mode nil)))) | |
460 (remove-hook 'reftex-mode-hook 'reftex-isearch-minor-mode))) | |
461 ;; Force modeline redisplay. | |
462 (set-buffer-modified-p (buffer-modified-p)))) | |
463 | |
464 (add-minor-mode 'reftex-isearch-minor-mode "/I" nil nil | |
465 'reftex-isearch-minor-mode) | |
466 | |
341 ;;; arch-tag: 2dbf7633-92c8-4340-8656-7aa019d0f80d | 467 ;;; arch-tag: 2dbf7633-92c8-4340-8656-7aa019d0f80d |
342 ;;; reftex-global.el ends here | 468 ;;; reftex-global.el ends here |