Re: Changes to preview-latex
Masayuki Ataka <[email protected]> Wed, 16 Mar 2005 18:23:13 +0900 (JST)
| Newsgroups | gmane.emacs.auc-tex |
|---|---|
| Message-ID | <[email protected]> |
From: Masayuki Ataka <[email protected]> Subject: Re: Changes to preview-latex Date: Tue, 15 Mar 2005 11:39:18 +0900 (JST) > From: David Kastrup <[email protected]> > > I have not yet made a decision about that. And I think it very > > unfortunate if preview.el requires tex-fold.el to be loaded. If we > > need to place overlay priorities for some reason, I think we should > > try to figure out a system where preview.el can place its respective > > priorities without consulting with tex-fold.el. > > > > Can we figure out some proper scheme for that? I don't know the > > details of the problem that we need to solve here. > > How about copying neccessary code from tex-fold.el into > preview.el? AFAICS, only the variable TeX-fold-priority-step > and the function TeX-fold-prioritize are required for the > calculation of priorities. Ah, It's a bad idea just copying a variable and a function, because we have the two functions in one package. Once one of them are changed, we will be in the trouble. > Of courese, we should maintain the one code in two files. This is a second idea. * Use TeX-fold-prioritize if tex-fold.el is loaded, else use preview-prioritize which is copied from tex-fold.el. (In these cases, new preview.el requires CVS tex-fold.el) How do you think, David and Ralf? 2005-03-16 Masayuki Ataka <[email protected]> * preview.el (TeX-fold-prioritize): Removed. (preview-priority-step): New variable. (preview-prioritize): New function. (preview-place-preview, preview-reinstate-preview): Use it. *** preview.el 15 3 2005 13:05:46 +0900 1.240 --- preview.el 16 3 2005 17:52:01 +0900 *************** *** 41,48 **** ;;; Code: - (autoload 'TeX-fold-prioritize "tex-fold" no-doc t) - (eval-when-compile (require 'tex-site) (require 'tex-buf) --- 41,46 ---- *************** *** 1957,1963 **** to the close hook." (preview-clearout start end tempdir) (let ((ov (make-overlay start end nil nil nil))) ! (overlay-put ov 'priority (TeX-fold-prioritize start end)) (overlay-put ov 'preview-map (preview-make-clickable nil nil nil --- 1955,1963 ---- to the close hook." (preview-clearout start end tempdir) (let ((ov (make-overlay start end nil nil nil))) ! (if (fboundp 'TeX-fold-prioritize) ! (overlay-put ov 'priority (TeX-fold-prioritize start end)) ! (overlay-put ov 'priority (preview-prioritize start end))) (overlay-put ov 'preview-map (preview-make-clickable nil nil nil *************** *** 2035,2041 **** (setcar (nthcdr 2 TeX-active-tempdir) (1+ (nth 2 TeX-active-tempdir))) (setcdr filename TeX-active-tempdir) (let ((ov (make-overlay start end nil nil nil))) ! (overlay-put ov 'priority (TeX-fold-prioritize start end)) (overlay-put ov 'preview-map (preview-make-clickable nil nil nil --- 2035,2043 ---- (setcar (nthcdr 2 TeX-active-tempdir) (1+ (nth 2 TeX-active-tempdir))) (setcdr filename TeX-active-tempdir) (let ((ov (make-overlay start end nil nil nil))) ! (if (fboundp 'TeX-fold-prioritize) ! (overlay-put ov 'priority (TeX-fold-prioritize start end)) ! (overlay-put ov 'priority (preview-prioritize start end))) (overlay-put ov 'preview-map (preview-make-clickable nil nil nil *************** *** 3356,3360 **** --- 3358,3393 ---- (makunbound 'preview-compatibility-macros) + ;; The content of `preview-priority-step' and `preview-prioritize' was copied + ;; from `tex-fold.el' (CVS AUCTeX March 2005) and adapted to the needs of + ;; preview-latex. + + (defvar preview-priority-step 16 + "Numerical difference of priorities between nested overlays. + The step should be big enough to allow setting a priority for new + overlays between two existing ones.") + + (defun preview-prioritize (start end) + "Calculate a priority for an overlay extending from START to END. + The calculated priority is lower than the minimum of priorities + of surrounding overlays and higher than the maximum of enclosed + overlays." + (let (outer-priority inner-priority) + (dolist (ov (overlays-in start end)) + (when (eq (overlay-get ov 'category) 'preview-overlay) + (let ((ov-priority (overlay-get ov 'priority))) + (if (>= (overlay-start ov) start) + (setq inner-priority (max ov-priority (or inner-priority + ov-priority))) + (setq outer-priority (min ov-priority (or outer-priority + ov-priority))))))) + (cond ((and inner-priority (not outer-priority)) + (+ inner-priority preview-priority-step)) + ((and (not inner-priority) outer-priority) + (/ outer-priority 2)) + ((and inner-priority outer-priority) + (/ (- outer-priority inner-priority) 2)) + (t preview-priority-step)))) + (provide 'preview) ;;; preview.el ends here