/[emacs]/emacs/lisp/textmodes/reftex-global.el
ViewVC logotype

Diff of /emacs/lisp/textmodes/reftex-global.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.17 by cdominik, Fri Jan 14 10:12:03 2005 UTC revision 1.18 by cdominik, Wed Jan 26 08:28:31 2005 UTC
# Line 338  Also checks if buffers visiting the file Line 338  Also checks if buffers visiting the file
338                                (buffer-name buf)))                                (buffer-name buf)))
339              (error "Abort"))))))              (error "Abort"))))))
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    
467  ;;; arch-tag: 2dbf7633-92c8-4340-8656-7aa019d0f80d  ;;; arch-tag: 2dbf7633-92c8-4340-8656-7aa019d0f80d
468  ;;; reftex-global.el ends here  ;;; reftex-global.el ends here

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26