178 |
(define-key map "\C-c\C-or" 'TeX-fold-clearout-region) |
(define-key map "\C-c\C-or" 'TeX-fold-clearout-region) |
179 |
(define-key map "\C-c\C-op" 'TeX-fold-clearout-paragraph) |
(define-key map "\C-c\C-op" 'TeX-fold-clearout-paragraph) |
180 |
(define-key map "\C-c\C-oi" 'TeX-fold-clearout-item) |
(define-key map "\C-c\C-oi" 'TeX-fold-clearout-item) |
|
;; To be removed |
|
|
(define-key map "\C-c\C-o\C-x" 'TeX-fold-clearout-buffer) |
|
|
(define-key map "\C-c\C-o\C-c" 'TeX-fold-clearout-item) |
|
181 |
map)) |
map)) |
182 |
|
|
183 |
|
|
269 |
(let* ((item-start (match-beginning 0)) |
(let* ((item-start (match-beginning 0)) |
270 |
(display-string-spec (cadr (assoc (match-string 1) |
(display-string-spec (cadr (assoc (match-string 1) |
271 |
fold-list))) |
fold-list))) |
272 |
(item-end (cond ((and (eq type 'env) |
(item-end (TeX-fold-item-end item-start type)) |
|
(eq major-mode 'context-mode)) |
|
|
(save-excursion |
|
|
(goto-char (match-end 0)) |
|
|
(ConTeXt-find-matching-stop) |
|
|
(point))) |
|
|
((and (eq type 'env) |
|
|
(eq major-mode 'texinfo-mode)) |
|
|
(save-excursion |
|
|
(goto-char (match-end 0)) |
|
|
(Texinfo-find-env-end) |
|
|
(point))) |
|
|
((eq type 'env) |
|
|
(save-excursion |
|
|
(goto-char (match-end 0)) |
|
|
(LaTeX-find-matching-end) |
|
|
(point))) |
|
|
(t |
|
|
(save-excursion |
|
|
(goto-char item-start) |
|
|
(TeX-find-macro-end))))) |
|
|
(display-string (if (integerp display-string-spec) |
|
|
(or (TeX-fold-macro-nth-arg |
|
|
display-string-spec |
|
|
item-start |
|
|
(when (eq type 'macro) |
|
|
item-end)) |
|
|
"[Error: No content found]") |
|
|
display-string-spec)) |
|
|
;; (apply #'propertize |
|
|
;; display-string-spec |
|
|
;; (text-properties-at |
|
|
;; (point))))) |
|
273 |
(ov (TeX-fold-make-overlay item-start item-end type |
(ov (TeX-fold-make-overlay item-start item-end type |
274 |
display-string-spec |
display-string-spec))) |
|
display-string))) |
|
275 |
(TeX-fold-hide-item ov))))))))))) |
(TeX-fold-hide-item ov))))))))))) |
276 |
|
|
277 |
(defun TeX-fold-macro () |
(defun TeX-fold-macro () |
349 |
(if (eq type 'env) |
(if (eq type 'env) |
350 |
TeX-fold-unspec-env-display-string |
TeX-fold-unspec-env-display-string |
351 |
TeX-fold-unspec-macro-display-string)))) |
TeX-fold-unspec-macro-display-string)))) |
352 |
(item-end (cond ((and (eq type 'env) |
(item-end (TeX-fold-item-end item-start type)) |
|
(eq major-mode 'context-mode)) |
|
|
(save-excursion |
|
|
(goto-char (match-end 0)) |
|
|
(ConTeXt-find-matching-stop) |
|
|
(point))) |
|
|
((and (eq type 'env) |
|
|
(eq major-mode 'texinfo-mode)) |
|
|
(save-excursion |
|
|
(goto-char (match-end 0)) |
|
|
(Texinfo-find-env-end) |
|
|
(point))) |
|
|
((eq type 'env) |
|
|
(save-excursion |
|
|
(goto-char (match-end 0)) |
|
|
(LaTeX-find-matching-end) |
|
|
(point))) |
|
|
(t |
|
|
(save-excursion |
|
|
(goto-char item-start) |
|
|
(TeX-find-macro-end))))) |
|
|
(display-string (if (integerp display-string-spec) |
|
|
(or (TeX-fold-macro-nth-arg |
|
|
display-string-spec |
|
|
item-start (when (eq type 'macro) |
|
|
item-end)) |
|
|
"[Error: No content found]") |
|
|
display-string-spec)) |
|
|
;; (apply #'propertize display-string-spec |
|
|
;; (text-properties-at (point))))) |
|
353 |
(ov (TeX-fold-make-overlay item-start item-end type |
(ov (TeX-fold-make-overlay item-start item-end type |
354 |
display-string-spec |
display-string-spec))) |
|
display-string))) |
|
355 |
(TeX-fold-hide-item ov)))))) |
(TeX-fold-hide-item ov)))))) |
356 |
|
|
357 |
|
|
358 |
;;; Utilities for folding |
;;; Utilities |
359 |
|
|
360 |
(defun TeX-fold-make-overlay (ov-start ov-end type |
(defun TeX-fold-make-overlay (ov-start ov-end type display-string-spec) |
361 |
display-string-spec display-string) |
"Make a TeX-fold overlay extending from OV-START to OV-END. |
362 |
"Make an overlay to cover the item. |
TYPE is a symbol which is used to describe the content to hide |
363 |
The overlay will reach from OV-START to OV-END and will display |
and may be 'macro for macros and 'env for environments. |
364 |
the string part of DISPLAY-STRING which has to be a string or a |
DISPLAY-STRING-SPEC is the original specification of the display |
365 |
list where the first item is a string and the second a face or |
string in the variables `TeX-fold-macro-spec-list' or |
366 |
nil. DISPLAY-STRING-SPEC is the original specification of the |
`TeX-fold-env-spec-list' and may be a string or an integer." |
367 |
display string in the variables `TeX-fold-macro-spec-list' or |
(let ((ov (make-overlay ov-start ov-end (current-buffer) t nil))) |
|
`TeX-fold-env-spec-list' and may be a string or an integer. TYPE |
|
|
is a symbol which is used to describe the content to hide and may |
|
|
be 'macro for macros and 'env for environments. |
|
|
|
|
|
The position of the end of the overlay and its display string may |
|
|
be altered to prevent overfull lines." |
|
|
(let* ((face (when (listp display-string) |
|
|
(cadr display-string))) |
|
|
(display-string (if (listp display-string) |
|
|
(car display-string) |
|
|
display-string)) |
|
|
(overfull (and (not (featurep 'xemacs)) ; Linebreaks in glyphs don't |
|
|
; work in XEmacs anyway. |
|
|
(save-excursion |
|
|
(goto-char ov-end) |
|
|
(search-backward "\n" ov-start t)) |
|
|
(not (string-match "\n" display-string)) |
|
|
(> (+ (- ov-start |
|
|
(save-excursion |
|
|
(goto-char ov-start) |
|
|
(line-beginning-position))) |
|
|
(length display-string) |
|
|
(- (save-excursion |
|
|
(goto-char ov-end) |
|
|
(line-end-position)) |
|
|
ov-end)) |
|
|
(current-fill-column)))) |
|
|
(ov-end (if overfull |
|
|
(save-excursion |
|
|
(goto-char ov-end) |
|
|
(skip-chars-forward " \t") |
|
|
(point)) |
|
|
ov-end)) |
|
|
(display-string (concat display-string (when overfull "\n"))) |
|
|
(priority (TeX-overlay-prioritize ov-start ov-end)) |
|
|
(ov (make-overlay ov-start ov-end (current-buffer) t nil))) |
|
368 |
(overlay-put ov 'category 'TeX-fold) |
(overlay-put ov 'category 'TeX-fold) |
369 |
(overlay-put ov 'priority priority) |
(overlay-put ov 'priority (TeX-overlay-prioritize ov-start ov-end)) |
370 |
(overlay-put ov 'evaporate t) |
(overlay-put ov 'evaporate t) |
|
(when font-lock-mode |
|
|
(overlay-put ov 'TeX-fold-face face)) |
|
371 |
(overlay-put ov 'TeX-fold-type type) |
(overlay-put ov 'TeX-fold-type type) |
372 |
(overlay-put ov 'TeX-fold-display-string-spec display-string-spec) |
(overlay-put ov 'TeX-fold-display-string-spec display-string-spec) |
|
(overlay-put ov 'TeX-fold-display-string display-string) |
|
373 |
ov)) |
ov)) |
374 |
|
|
375 |
|
(defun TeX-fold-item-end (start type) |
376 |
|
"Return the end of an item of type TYPE starting at START. |
377 |
|
TYPE can be either 'env for environments or 'macro for macros." |
378 |
|
(save-excursion |
379 |
|
(cond ((and (eq type 'env) |
380 |
|
(eq major-mode 'context-mode)) |
381 |
|
(goto-char start) |
382 |
|
(ConTeXt-find-matching-stop) |
383 |
|
(point)) |
384 |
|
((and (eq type 'env) |
385 |
|
(eq major-mode 'texinfo-mode)) |
386 |
|
(goto-char (1+ start)) |
387 |
|
(Texinfo-find-env-end) |
388 |
|
(point)) |
389 |
|
((eq type 'env) |
390 |
|
(goto-char (1+ start)) |
391 |
|
(LaTeX-find-matching-end) |
392 |
|
(point)) |
393 |
|
(t |
394 |
|
(goto-char start) |
395 |
|
(TeX-find-macro-end))))) |
396 |
|
|
397 |
|
(defun TeX-fold-overfull-p (ov-start ov-end display-string) |
398 |
|
"Return t if an overfull line will result after adding an overlay. |
399 |
|
The overlay extends from OV-START to OV-END and will display the |
400 |
|
string DISPLAY-STRING." |
401 |
|
(and (not (featurep 'xemacs)) ; Linebreaks in glyphs don't |
402 |
|
; work in XEmacs anyway. |
403 |
|
(save-excursion |
404 |
|
(goto-char ov-end) |
405 |
|
(search-backward "\n" ov-start t)) |
406 |
|
(not (string-match "\n" display-string)) |
407 |
|
(> (+ (- ov-start |
408 |
|
(save-excursion |
409 |
|
(goto-char ov-start) |
410 |
|
(line-beginning-position))) |
411 |
|
(length display-string) |
412 |
|
(- (save-excursion |
413 |
|
(goto-char ov-end) |
414 |
|
(line-end-position)) |
415 |
|
ov-end)) |
416 |
|
(current-fill-column)))) |
417 |
|
|
418 |
(defun TeX-fold-macro-nth-arg (n macro-start &optional macro-end) |
(defun TeX-fold-macro-nth-arg (n macro-start &optional macro-end) |
419 |
"Return a property list of the argument number N of a macro. |
"Return a property list of the argument number N of a macro. |
420 |
The start of the macro to examine is given by MACRO-START, its |
The start of the macro to examine is given by MACRO-START, its |
483 |
(setq ov (car overlays) |
(setq ov (car overlays) |
484 |
overlays (cdr overlays)) |
overlays (cdr overlays)) |
485 |
;; Add the display string of the overlay. |
;; Add the display string of the overlay. |
486 |
(setq result (concat result |
(setq result (concat result (overlay-get ov 'display))) |
|
(overlay-get ov 'TeX-fold-display-string))) |
|
487 |
;; Remove overlays contained in the current one. |
;; Remove overlays contained in the current one. |
488 |
(dolist (elt overlays) |
(dolist (elt overlays) |
489 |
(when (< (overlay-start elt) (overlay-end ov)) |
(when (< (overlay-start elt) (overlay-end ov)) |
516 |
(when (> end spill) (setq result (concat result "..."))) |
(when (> end spill) (setq result (concat result "..."))) |
517 |
result)) |
result)) |
518 |
|
|
519 |
|
(defun TeX-fold-update-at-point () |
520 |
|
"Update all TeX-fold overlays at point displaying computed content." |
521 |
|
(let (overlays) |
522 |
|
;; Get all overlays at point under our control. |
523 |
|
(dolist (ov (overlays-at (point))) |
524 |
|
(when (and (eq (overlay-get ov 'category) 'TeX-fold) |
525 |
|
(numberp (overlay-get ov 'TeX-fold-display-string-spec))) |
526 |
|
(add-to-list 'overlays ov))) |
527 |
|
(when overlays |
528 |
|
;; Sort list according to descending starts. |
529 |
|
(setq overlays (sort (copy-sequence overlays) |
530 |
|
(lambda (a b) |
531 |
|
(> (overlay-start a) (overlay-start b))))) |
532 |
|
(dolist (ov overlays) |
533 |
|
(TeX-fold-hide-item ov))))) |
534 |
|
|
535 |
|
|
536 |
;;; Removal |
;;; Removal |
537 |
|
|
577 |
(defun TeX-fold-hide-item (ov) |
(defun TeX-fold-hide-item (ov) |
578 |
"Hide a single macro or environment. |
"Hide a single macro or environment. |
579 |
That means, put respective properties onto overlay OV." |
That means, put respective properties onto overlay OV." |
580 |
(let* ((display-string-spec (overlay-get ov 'TeX-fold-display-string-spec)) |
(let* ((ov-start (overlay-start ov)) |
581 |
(display-string (if (stringp display-string-spec) |
(ov-end (overlay-end ov)) |
582 |
(overlay-get ov 'TeX-fold-display-string) |
(spec (overlay-get ov 'TeX-fold-display-string-spec)) |
583 |
;; If the display string specification is |
(computed (if (stringp spec) |
584 |
;; an integer, recompute the display string |
spec |
585 |
;; in order to have an up-to-date string if |
(or (TeX-fold-macro-nth-arg spec ov-start ov-end) |
586 |
;; the content has changed. |
"[Error: No content found]"))) |
587 |
(or (TeX-fold-macro-nth-arg |
(display-string (if (listp computed) (car computed) computed)) |
588 |
display-string-spec (overlay-start ov) |
(face (when (listp computed) (cadr computed)))) |
589 |
(when (eq (overlay-get ov 'TeX-fold-type) |
;; Add a linebreak to the display string and adjust the overlay end |
590 |
'macro) |
;; in case of an overfull line. |
591 |
(overlay-end ov))) |
(when (TeX-fold-overfull-p ov-start ov-end display-string) |
592 |
"[Error: No content found]")))) |
(setq display-string (concat display-string "\n")) |
593 |
|
(move-overlay ov ov-start (save-excursion |
594 |
|
(goto-char ov-end) |
595 |
|
(skip-chars-forward " \t") |
596 |
|
(point)))) |
597 |
(overlay-put ov 'mouse-face 'highlight) |
(overlay-put ov 'mouse-face 'highlight) |
598 |
|
(overlay-put ov 'display display-string) |
599 |
(if (featurep 'xemacs) |
(if (featurep 'xemacs) |
600 |
(let ((glyph (make-glyph (if (listp display-string) |
(let ((glyph (make-glyph (if (listp display-string) |
601 |
(car display-string) |
(car display-string) |
602 |
display-string))) |
display-string)))) |
|
(face (overlay-get ov 'TeX-fold-face))) |
|
603 |
(overlay-put ov 'invisible t) |
(overlay-put ov 'invisible t) |
604 |
(when font-lock-mode |
(when font-lock-mode |
605 |
(if face |
(if face |
608 |
(set-extent-property ov 'end-glyph glyph)) |
(set-extent-property ov 'end-glyph glyph)) |
609 |
(when font-lock-mode |
(when font-lock-mode |
610 |
(overlay-put ov 'face TeX-fold-folded-face)) |
(overlay-put ov 'face TeX-fold-folded-face)) |
|
(overlay-put ov 'display display-string) |
|
611 |
(unless (zerop TeX-fold-help-echo-max-length) |
(unless (zerop TeX-fold-help-echo-max-length) |
612 |
(overlay-put ov 'help-echo (TeX-fold-make-help-echo |
(overlay-put ov 'help-echo (TeX-fold-make-help-echo |
613 |
(overlay-start ov) (overlay-end ov))))))) |
(overlay-start ov) (overlay-end ov))))))) |
698 |
;;; The mode |
;;; The mode |
699 |
|
|
700 |
;;; This autoload cookie had to be changed because of XEmacs. This is |
;;; This autoload cookie had to be changed because of XEmacs. This is |
701 |
;;; very dissatisfactory, because we now don't have the doc string |
;;; very dissatisfactory, because we now don't have the full doc string |
702 |
;;; available to tell people what to expect when using this mode |
;;; available to tell people what to expect when using this mode |
703 |
;;; before loading it. |
;;; before loading it. |
704 |
|
|
713 |
(if TeX-fold-mode |
(if TeX-fold-mode |
714 |
(progn |
(progn |
715 |
(set (make-local-variable 'search-invisible) t) |
(set (make-local-variable 'search-invisible) t) |
716 |
(add-hook 'post-command-hook 'TeX-fold-post-command nil t)) |
(add-hook 'post-command-hook 'TeX-fold-post-command nil t) |
717 |
|
(add-hook 'LaTeX-fill-newline-hook 'TeX-fold-update-at-point nil t)) |
718 |
(kill-local-variable 'search-invisible) |
(kill-local-variable 'search-invisible) |
719 |
(remove-hook 'post-command-hook 'TeX-fold-post-command t) |
(remove-hook 'post-command-hook 'TeX-fold-post-command t) |
720 |
|
(remove-hook 'LaTeX-fill-newline-hook 'TeX-fold-update-at-point t) |
721 |
(TeX-fold-clearout-buffer)) |
(TeX-fold-clearout-buffer)) |
722 |
(TeX-set-mode-name)) |
(TeX-set-mode-name)) |
723 |
|
|