comparison lisp/simple.el @ 278:90d73dddcdc4 r21-0b37

Import from CVS: tag r21-0b37
author cvs
date Mon, 13 Aug 2007 10:31:29 +0200
parents c5d627a313b1
children 7df0dd720c89
comparison
equal deleted inserted replaced
277:cfdf3ff11843 278:90d73dddcdc4
567 ;; XEmacs 567 ;; XEmacs
568 (defun count-words-buffer (buffer) 568 (defun count-words-buffer (buffer)
569 "Print the number of words in BUFFER. 569 "Print the number of words in BUFFER.
570 If called noninteractively, the value is returned rather than printed. 570 If called noninteractively, the value is returned rather than printed.
571 BUFFER defaults to the current buffer." 571 BUFFER defaults to the current buffer."
572 (interactive "bBuffer: ") 572 (interactive "_bBuffer: ")
573 (let ((words (count-words-region (point-min) (point-max) buffer))) 573 (let ((words (count-words-region (point-min) (point-max) buffer)))
574 (when (interactive-p) 574 (when (interactive-p)
575 (message "Buffer has %d words" words)) 575 (message "Buffer has %d words" words))
576 words)) 576 words))
577 577
578 ;; XEmacs 578 ;; XEmacs
579 (defun count-words-region (start end &optional buffer) 579 (defun count-words-region (start end &optional buffer)
580 "Print the number of words in region between START and END in BUFFER. 580 "Print the number of words in region between START and END in BUFFER.
581 If called noninteractively, the value is returned rather than printed. 581 If called noninteractively, the value is returned rather than printed.
582 BUFFER defaults to the current buffer." 582 BUFFER defaults to the current buffer."
583 (interactive "r") 583 (interactive "_r")
584 (save-excursion 584 (save-excursion
585 (set-buffer (or buffer (current-buffer))) 585 (set-buffer (or buffer (current-buffer)))
586 (let ((words 0)) 586 (let ((words 0))
587 (goto-char start) 587 (goto-char start)
588 (while (< (point) end) 588 (while (< (point) end)
608 (let ((cnt (count-lines (point-min) (point-max)))) 608 (let ((cnt (count-lines (point-min) (point-max))))
609 (message "Buffer has %d lines, %d characters" 609 (message "Buffer has %d lines, %d characters"
610 cnt (- (point-max) (point-min))) 610 cnt (- (point-max) (point-min)))
611 cnt))) 611 cnt)))
612 612
613 ;;; Modified by Bob Weiner, 8/24/95, to print narrowed line number also.
614 ;;; Expanded by Bob Weiner, Altrasoft, on 02/12/1997
613 (defun what-line () 615 (defun what-line ()
614 "Print the current buffer line number and narrowed line number of point." 616 "Print the following variants of the line number of point:
617 Region line - displayed line within the active region
618 Collapsed line - includes only selectively displayed lines;
619 Buffer line - physical line in the buffer;
620 Narrowed line - line number from the start of the buffer narrowing."
615 ;; XEmacs change 621 ;; XEmacs change
616 (interactive "_") 622 (interactive "_")
617 (let ((opoint (point)) start) 623 (let ((opoint (point)) start)
618 (save-excursion 624 (save-excursion
619 (save-restriction 625 (save-restriction
620 (goto-char (point-min)) 626 (if (region-active-p)
627 (goto-char (region-beginning))
628 (goto-char (point-min)))
621 (widen) 629 (widen)
622 (beginning-of-line) 630 (beginning-of-line)
623 (setq start (point)) 631 (setq start (point))
624 (goto-char opoint) 632 (goto-char opoint)
625 (beginning-of-line) 633 (beginning-of-line)
626 (if (/= start 1) 634 (let* ((buffer-line (1+ (count-lines 1 (point))))
627 (message "Line %d (narrowed line %d)" 635 (narrowed-p (or (/= start 1)
628 (1+ (count-lines 1 (point))) 636 (/= (point-max) (1+ (buffer-size)))))
629 (1+ (count-lines start (point)))) 637 (narrowed-line (if narrowed-p (1+ (count-lines start (point)))))
630 (message "Line %d" (1+ (count-lines 1 (point))))))))) 638 (selective-line (if selective-display
631 639 (1+ (count-lines start (point) t))))
632 640 (region-line (if (region-active-p)
633 (defun count-lines (start end) 641 (1+ (count-lines start (point) selective-display)))))
642 (cond (region-line
643 (message "Region line %d; Buffer line %d"
644 region-line buffer-line))
645 ((and narrowed-p selective-line (/= selective-line narrowed-line))
646 ;; buffer narrowed and some lines selectively displayed
647 (message "Collapsed line %d; Buffer line %d; Narrowed line %d"
648 selective-line buffer-line narrowed-line))
649 (narrowed-p
650 ;; buffer narrowed
651 (message "Buffer line %d; Narrowed line %d"
652 buffer-line narrowed-line))
653 ((and selective-line (/= selective-line buffer-line))
654 ;; some lines selectively displayed
655 (message "Collapsed line %d; Buffer line %d"
656 selective-line buffer-line))
657 (t
658 ;; give a basic line count
659 (message "Line %d" buffer-line)))))))
660 (setq zmacs-region-stays t))
661
662 ;;; Bob Weiner, Altrasoft, 02/12/1998
663 ;;; Added the 3rd arg in `count-lines' to conditionalize the counting of
664 ;;; collapsed lines.
665 (defun count-lines (start end &optional ignore-invisible-lines-flag)
634 "Return number of lines between START and END. 666 "Return number of lines between START and END.
635 This is usually the number of newlines between them, 667 This is usually the number of newlines between them,
636 but can be one more if START is not equal to END 668 but can be one more if START is not equal to END
637 and the greater of them is not at the start of a line." 669 and the greater of them is not at the start of a line.
670
671 With optional IGNORE-INVISIBLE-LINES-FLAG non-nil, lines collapsed with
672 selective-display are excluded from the line count."
638 (save-excursion 673 (save-excursion
639 (save-restriction 674 (save-restriction
640 (narrow-to-region start end) 675 (narrow-to-region start end)
641 (goto-char (point-min)) 676 (goto-char (point-min))
642 (if (eq selective-display t) 677 (if (and (not ignore-invisible-lines-flag) (eq selective-display t))
643 (save-match-data 678 (save-match-data
644 (let ((done 0)) 679 (let ((done 0))
645 (while (re-search-forward "[\n\C-m]" nil t 40) 680 (while (re-search-forward "[\n\C-m]" nil t 40)
646 (setq done (+ 40 done))) 681 (setq done (+ 40 done)))
647 (while (re-search-forward "[\n\C-m]" nil t 1) 682 (while (re-search-forward "[\n\C-m]" nil t 1)
2760 (insert fill-prefix)) 2795 (insert fill-prefix))
2761 ;; #### - Eric Eide reverts to v18 semantics for this function in 2796 ;; #### - Eric Eide reverts to v18 semantics for this function in
2762 ;; fa-extras, which I'm not gonna do. His changes are to (1) execute 2797 ;; fa-extras, which I'm not gonna do. His changes are to (1) execute
2763 ;; the save-excursion below unconditionally, and (2) uncomment the check 2798 ;; the save-excursion below unconditionally, and (2) uncomment the check
2764 ;; for (not comment-multi-line) further below. --Stig 2799 ;; for (not comment-multi-line) further below. --Stig
2765 ;;### jhod: probably need to fix this for kinsoku processing 2800 ;;#### jhod: probably need to fix this for kinsoku processing
2766 (if (not comment-multi-line) 2801 (if (not comment-multi-line)
2767 (save-excursion 2802 (save-excursion
2768 (if (and comment-start-skip 2803 (if (and comment-start-skip
2769 (let ((opoint (point))) 2804 (let ((opoint (point)))
2770 (forward-line -1) 2805 (forward-line -1)
3601 if it satisfies the `log-message-filter-function'. 3636 if it satisfies the `log-message-filter-function'.
3602 3637
3603 For use on `remove-message-hook'." 3638 For use on `remove-message-hook'."
3604 (when (and (not noninteractive) 3639 (when (and (not noninteractive)
3605 (funcall log-message-filter-function label message)) 3640 (funcall log-message-filter-function label message))
3606 (with-current-buffer (get-buffer-create " *Message-Log*") 3641 ;; Use save-excursion rather than save-current-buffer because we
3642 ;; change the value of point.
3643 (save-excursion
3644 (set-buffer (get-buffer-create " *Message-Log*"))
3607 (goto-char (point-max)) 3645 (goto-char (point-max))
3608 ;; (insert (concat (upcase (symbol-name label)) ": " message "\n")) 3646 ;(insert (concat (upcase (symbol-name label)) ": " message "\n"))
3609 (insert message "\n") 3647 (let (extent)
3648 ;; Mark multiline message with an extent, which `view-lossage'
3649 ;; will recognize.
3650 (when (string-match "\n" message)
3651 (setq extent (make-extent (point) (point)))
3652 (set-extent-properties extent '(end-open nil message-multiline t)))
3653 (insert message "\n")
3654 (when extent
3655 (set-extent-property extent 'end-open t)))
3610 (when (> (point-max) (max log-message-max-size (point-min))) 3656 (when (> (point-max) (max log-message-max-size (point-min)))
3611 ;; trim log to ~90% of max size 3657 ;; Trim log to ~90% of max size.
3612 (goto-char (max (- (point-max) 3658 (goto-char (max (- (point-max)
3613 (truncate (* 0.9 log-message-max-size))) 3659 (truncate (* 0.9 log-message-max-size)))
3614 (point-min))) 3660 (point-min)))
3615 (forward-line 1) 3661 (forward-line 1)
3616 (delete-region (point-min) (point)))))) 3662 (delete-region (point-min) (point))))))
3642 Unless you need the return value or you need to specify a label, 3688 Unless you need the return value or you need to specify a label,
3643 you should just use (message nil)." 3689 you should just use (message nil)."
3644 (or frame (setq frame (selected-frame))) 3690 (or frame (setq frame (selected-frame)))
3645 (let ((clear-stream (and message-stack (eq 'stream (frame-type frame))))) 3691 (let ((clear-stream (and message-stack (eq 'stream (frame-type frame)))))
3646 (remove-message label frame) 3692 (remove-message label frame)
3647 (let ((buffer (get-buffer " *Echo Area*")) 3693 (let ((inhibit-read-only t)
3648 (inhibit-read-only t)
3649 (zmacs-region-stays zmacs-region-stays)) ; preserve from change 3694 (zmacs-region-stays zmacs-region-stays)) ; preserve from change
3650 (erase-buffer buffer)) 3695 (erase-buffer " *Echo Area*"))
3651 (if clear-stream 3696 (if clear-stream
3652 (send-string-to-terminal ?\n stdout-p)) 3697 (send-string-to-terminal ?\n stdout-p))
3653 (if no-restore 3698 (if no-restore
3654 nil ; just preparing to put another msg up 3699 nil ; just preparing to put another msg up
3655 (if message-stack 3700 (if message-stack
3656 (let ((oldmsg (cdr (car message-stack)))) 3701 (let ((oldmsg (cdr (car message-stack))))
3657 (raw-append-message oldmsg frame stdout-p) 3702 (raw-append-message oldmsg frame stdout-p)
3658 oldmsg) 3703 oldmsg)
3659 ;; ### should we (redisplay-echo-area) here? messes some things up. 3704 ;; #### Should we (redisplay-echo-area) here? Messes some
3705 ;; things up.
3660 nil)))) 3706 nil))))
3661 3707
3662 (defun remove-message (&optional label frame) 3708 (defun remove-message (&optional label frame)
3663 ;; If label is nil, we want to remove all matching messages. 3709 ;; If label is nil, we want to remove all matching messages.
3664 ;; Must reverse the stack first to log them in the right order. 3710 ;; Must reverse the stack first to log them in the right order.
3665 (let ((log nil)) 3711 (let ((log nil))
3666 (while (and message-stack 3712 (while (and message-stack
3667 (or (null label) ; null label means clear whole stack 3713 (or (null label) ; null label means clear whole stack
3668 (eq label (car (car message-stack))))) 3714 (eq label (car (car message-stack)))))
3669 (setq log (cons (car message-stack) log)) 3715 (push (car message-stack) log)
3670 (setq message-stack (cdr message-stack))) 3716 (setq message-stack (cdr message-stack)))
3671 (let ((s message-stack)) 3717 (let ((s message-stack))
3672 (while (cdr s) 3718 (while (cdr s)
3673 (let ((msg (car (cdr s)))) 3719 (let ((msg (car (cdr s))))
3674 (if (eq label (car msg)) 3720 (if (eq label (car msg))
3675 (progn 3721 (progn
3676 (setq log (cons msg log)) 3722 (push msg log)
3677 (setcdr s (cdr (cdr s)))) 3723 (setcdr s (cdr (cdr s))))
3678 (setq s (cdr s)))))) 3724 (setq s (cdr s))))))
3679 ;; (possibly) log each removed message 3725 ;; (possibly) log each removed message
3680 (while log 3726 (while log
3681 (condition-case e 3727 (condition-case e
3684 (error (setq remove-message-hook nil) 3730 (error (setq remove-message-hook nil)
3685 (lwarn 'message-log 'warning 3731 (lwarn 'message-log 'warning
3686 "Error caught in `remove-message-hook': %s" 3732 "Error caught in `remove-message-hook': %s"
3687 (error-message-string e)) 3733 (error-message-string e))
3688 (let ((inhibit-read-only t)) 3734 (let ((inhibit-read-only t))
3689 (erase-buffer (get-buffer " *Echo Area*"))) 3735 (erase-buffer " *Echo Area*"))
3690 (signal (car e) (cdr e)))) 3736 (signal (car e) (cdr e))))
3691 (setq log (cdr log))))) 3737 (setq log (cdr log)))))
3692 3738
3693 (defun append-message (label message &optional frame stdout-p) 3739 (defun append-message (label message &optional frame stdout-p)
3694 (or frame (setq frame (selected-frame))) 3740 (or frame (setq frame (selected-frame)))
3695 ;; add a new entry to the message-stack, or modify an existing one 3741 ;; Add a new entry to the message-stack, or modify an existing one
3696 (let ((top (car message-stack))) 3742 (let ((top (car message-stack)))
3697 (if (eq label (car top)) 3743 (if (eq label (car top))
3698 (setcdr top (concat (cdr top) message)) 3744 (setcdr top (concat (cdr top) message))
3699 (setq message-stack (cons (cons label message) message-stack)))) 3745 (push (cons label message) message-stack)))
3700 (raw-append-message message frame stdout-p)) 3746 (raw-append-message message frame stdout-p))
3701 3747
3702 ;; really append the message to the echo area. no fiddling with message-stack. 3748 ;; Really append the message to the echo area. no fiddling with
3749 ;; message-stack.
3703 (defun raw-append-message (message &optional frame stdout-p) 3750 (defun raw-append-message (message &optional frame stdout-p)
3704 (if (eq message "") nil 3751 (unless (equal message "")
3705 (let ((buffer (get-buffer " *Echo Area*")) 3752 (let ((inhibit-read-only t)
3706 (zmacs-region-stays zmacs-region-stays)) ; preserve from change 3753 (zmacs-region-stays zmacs-region-stays)) ; preserve from change
3707 (with-current-buffer buffer 3754 (insert-string message " *Echo Area*")
3708 (let ((inhibit-read-only t))
3709 (insert message)))
3710 ;; Conditionalizing on the device type in this way is not that clean, 3755 ;; Conditionalizing on the device type in this way is not that clean,
3711 ;; but neither is having a device method, as I originally implemented 3756 ;; but neither is having a device method, as I originally implemented
3712 ;; it: all non-stream devices behave in the same way. Perhaps 3757 ;; it: all non-stream devices behave in the same way. Perhaps
3713 ;; the cleanest way is to make the concept of a "redisplayable" 3758 ;; the cleanest way is to make the concept of a "redisplayable"
3714 ;; device, which stream devices are not. Look into this more if 3759 ;; device, which stream devices are not. Look into this more if
3716 ;; processes? printers?). 3761 ;; processes? printers?).
3717 3762
3718 ;; Don't redisplay the echo area if we are executing a macro. 3763 ;; Don't redisplay the echo area if we are executing a macro.
3719 (if (not executing-kbd-macro) 3764 (if (not executing-kbd-macro)
3720 (if (eq 'stream (frame-type frame)) 3765 (if (eq 'stream (frame-type frame))
3721 (send-string-to-terminal message stdout-p) 3766 (send-string-to-terminal message stdout-p (frame-device frame))
3722 (redisplay-echo-area)))))) 3767 (redisplay-echo-area))))))
3723 3768
3724 (defun display-message (label message &optional frame stdout-p) 3769 (defun display-message (label message &optional frame stdout-p)
3725 "Print a one-line message at the bottom of the frame. First argument 3770 "Print a one-line message at the bottom of the frame. First argument
3726 LABEL is an identifier for this message. MESSAGE is the string to display. 3771 LABEL is an identifier for this message. MESSAGE is the string to display.
3892 (or level (setq level 'warning)) 3937 (or level (setq level 'warning))
3893 (or (listp class) (setq class (list class))) 3938 (or (listp class) (setq class (list class)))
3894 (check-argument-type 'warning-level-p level) 3939 (check-argument-type 'warning-level-p level)
3895 (if (and (not (featurep 'infodock)) 3940 (if (and (not (featurep 'infodock))
3896 (not init-file-loaded)) 3941 (not init-file-loaded))
3897 (setq before-init-deferred-warnings 3942 (push (list class message level) before-init-deferred-warnings)
3898 (cons (list class message level) before-init-deferred-warnings))
3899 (catch 'ignored 3943 (catch 'ignored
3900 (let ((display-p t) 3944 (let ((display-p t)
3901 (level-num (cdr (assq level warning-level-alist)))) 3945 (level-num (cdr (assq level warning-level-alist))))
3902 (if (< level-num (cdr (assq log-warning-minimum-level 3946 (if (< level-num (cdr (assq log-warning-minimum-level
3903 warning-level-alist))) 3947 warning-level-alist)))