comparison lisp/ibuffer.el @ 44571:be1cb50b8859

(ibuffer-forward-line): Just skip header if we're only moving one line forward. (ibuffer-map-lines): Preserve point position even if we delete lines. Only call mapping functions with buffer and mark arguments; the other two were unused. (ibuffer-redisplay, ibuffer-update): Always skip special areas.
author Colin Walters <walters@gnu.org>
date Sun, 14 Apr 2002 01:50:57 +0000
parents 5fa7b088231f
children 9d84a456037d
comparison
equal deleted inserted replaced
44570:30d170360f38 44571:be1cb50b8859
824 (setq arg 1)) 824 (setq arg 1))
825 (beginning-of-line) 825 (beginning-of-line)
826 (when (or (eobp) 826 (when (or (eobp)
827 (get-text-property (point) 'ibuffer-summary)) 827 (get-text-property (point) 'ibuffer-summary))
828 (goto-char (point-min))) 828 (goto-char (point-min)))
829 (while (get-text-property (point) 'ibuffer-title) 829 (when (get-text-property (point) 'ibuffer-title)
830 (forward-line 1)) 830 (if (> arg 0)
831 (decf arg))
832 (while (get-text-property (point) 'ibuffer-title)
833 (forward-line 1)))
831 (if (< arg 0) 834 (if (< arg 0)
832 (ibuffer-backward-line (- arg)) 835 (ibuffer-backward-line (- arg))
833 (while (> arg 0) 836 (while (> arg 0)
834 (forward-line 1) 837 (forward-line 1)
835 (when (or (eobp) 838 (when (or (eobp)
1004 (ibuffer-map-lines function t)) 1007 (ibuffer-map-lines function t))
1005 1008
1006 (defun ibuffer-buffer-names-with-mark (mark) 1009 (defun ibuffer-buffer-names-with-mark (mark)
1007 (let ((ibuffer-buffer-names-with-mark-result nil)) 1010 (let ((ibuffer-buffer-names-with-mark-result nil))
1008 (ibuffer-map-lines-nomodify 1011 (ibuffer-map-lines-nomodify
1009 #'(lambda (buf mk beg end) 1012 #'(lambda (buf mk)
1010 (when (char-equal mark mk) 1013 (when (char-equal mark mk)
1011 (push (buffer-name buf) 1014 (push (buffer-name buf)
1012 ibuffer-buffer-names-with-mark-result)))) 1015 ibuffer-buffer-names-with-mark-result))))
1013 ibuffer-buffer-names-with-mark-result)) 1016 ibuffer-buffer-names-with-mark-result))
1014 1017
1019 (ibuffer-buffer-names-with-mark ibuffer-deletion-char)) 1022 (ibuffer-buffer-names-with-mark ibuffer-deletion-char))
1020 1023
1021 (defun ibuffer-count-marked-lines (&optional all) 1024 (defun ibuffer-count-marked-lines (&optional all)
1022 (if all 1025 (if all
1023 (ibuffer-map-lines-nomodify 1026 (ibuffer-map-lines-nomodify
1024 #'(lambda (buf mark beg end) 1027 #'(lambda (buf mark)
1025 (not (char-equal mark ? )))) 1028 (not (char-equal mark ? ))))
1026 (ibuffer-map-lines-nomodify 1029 (ibuffer-map-lines-nomodify
1027 #'(lambda (buf mark beg end) 1030 #'(lambda (buf mark)
1028 (char-equal mark ibuffer-marked-char))))) 1031 (char-equal mark ibuffer-marked-char)))))
1029 1032
1030 (defsubst ibuffer-count-deletion-lines () 1033 (defsubst ibuffer-count-deletion-lines ()
1031 (ibuffer-map-lines-nomodify 1034 (ibuffer-map-lines-nomodify
1032 #'(lambda (buf mark beg end) 1035 #'(lambda (buf mark)
1033 (char-equal mark ibuffer-deletion-char)))) 1036 (char-equal mark ibuffer-deletion-char))))
1034 1037
1035 (defsubst ibuffer-map-deletion-lines (func) 1038 (defsubst ibuffer-map-deletion-lines (func)
1036 (ibuffer-map-on-mark ibuffer-deletion-char func)) 1039 (ibuffer-map-on-mark ibuffer-deletion-char func))
1037 1040
1093 (if (= (ibuffer-count-marked-lines t) 0) 1096 (if (= (ibuffer-count-marked-lines t) 0)
1094 (message "No buffers marked; use 'm' to mark a buffer") 1097 (message "No buffers marked; use 'm' to mark a buffer")
1095 (cond 1098 (cond
1096 ((char-equal mark ibuffer-marked-char) 1099 ((char-equal mark ibuffer-marked-char)
1097 (ibuffer-map-marked-lines 1100 (ibuffer-map-marked-lines
1098 #'(lambda (buf mark beg end) 1101 #'(lambda (buf mark)
1099 (ibuffer-set-mark-1 ? ) 1102 (ibuffer-set-mark-1 ? )
1100 t))) 1103 t)))
1101 ((char-equal mark ibuffer-deletion-char) 1104 ((char-equal mark ibuffer-deletion-char)
1102 (ibuffer-map-deletion-lines 1105 (ibuffer-map-deletion-lines
1103 #'(lambda (buf mark beg end) 1106 #'(lambda (buf mark)
1104 (ibuffer-set-mark-1 ? ) 1107 (ibuffer-set-mark-1 ? )
1105 t))) 1108 t)))
1106 (t 1109 (t
1107 (ibuffer-map-lines 1110 (ibuffer-map-lines
1108 #'(lambda (buf mark beg end) 1111 #'(lambda (buf mark)
1109 (when (not (char-equal mark ? )) 1112 (when (not (char-equal mark ? ))
1110 (ibuffer-set-mark-1 ? )) 1113 (ibuffer-set-mark-1 ? ))
1111 t))))) 1114 t)))))
1112 (ibuffer-redisplay t)) 1115 (ibuffer-redisplay t))
1113 1116
1116 In other words, unmarked buffers become marked, and marked buffers 1119 In other words, unmarked buffers become marked, and marked buffers
1117 become unmarked." 1120 become unmarked."
1118 (interactive) 1121 (interactive)
1119 (let ((count 1122 (let ((count
1120 (ibuffer-map-lines 1123 (ibuffer-map-lines
1121 #'(lambda (buf mark beg end) 1124 #'(lambda (buf mark)
1122 (cond ((eq mark ibuffer-marked-char) 1125 (cond ((eq mark ibuffer-marked-char)
1123 (ibuffer-set-mark-1 ? ) 1126 (ibuffer-set-mark-1 ? )
1124 nil) 1127 nil)
1125 ((eq mark ? ) 1128 ((eq mark ? )
1126 (ibuffer-set-mark-1 ibuffer-marked-char) 1129 (ibuffer-set-mark-1 ibuffer-marked-char)
1594 (when ibuffer-shrink-to-minimum-size 1597 (when ibuffer-shrink-to-minimum-size
1595 (ibuffer-shrink-to-fit))))))) 1598 (ibuffer-shrink-to-fit)))))))
1596 1599
1597 (defun ibuffer-map-on-mark (mark func) 1600 (defun ibuffer-map-on-mark (mark func)
1598 (ibuffer-map-lines 1601 (ibuffer-map-lines
1599 #'(lambda (buf mk beg end) 1602 #'(lambda (buf mk)
1600 (if (char-equal mark mk) 1603 (if (char-equal mark mk)
1601 (funcall func buf mark beg end) 1604 (funcall func buf mark)
1602 nil)))) 1605 nil))))
1603 1606
1604 (defun ibuffer-map-lines (function &optional nomodify) 1607 (defun ibuffer-map-lines (function &optional nomodify)
1605 "Call FUNCTION for each buffer in an ibuffer. 1608 "Call FUNCTION for each buffer in an ibuffer.
1606 Don't set the ibuffer modification flag iff NOMODIFY is non-nil. 1609 Don't set the ibuffer modification flag iff NOMODIFY is non-nil.
1607 1610
1608 FUNCTION is called with four arguments: the buffer object itself, the 1611 FUNCTION is called with four arguments: the buffer object itself, the
1609 current mark symbol, and the beginning and ending line positions." 1612 current mark symbol, and the beginning and ending line positions."
1610 (assert (eq major-mode 'ibuffer-mode)) 1613 (assert (eq major-mode 'ibuffer-mode))
1611 (let ((curline (count-lines (point-min) 1614 (let ((orig-target-line (count-lines (point-min)
1612 (line-beginning-position))) 1615 (line-beginning-position)))
1613 (deleted-lines-count 0) 1616 (target-buf-count 0)
1614 (ibuffer-map-lines-total 0) 1617 (ibuffer-map-lines-total 0)
1615 (ibuffer-map-lines-count 0)) 1618 (ibuffer-map-lines-count 0))
1616 (unwind-protect 1619 (unwind-protect
1617 (progn 1620 (progn
1618 (setq buffer-read-only nil) 1621 (setq buffer-read-only nil)
1619 (goto-char (point-min)) 1622 (goto-char (point-min))
1620 (while (and (get-text-property (point) 'ibuffer-title) 1623 (ibuffer-forward-line 0)
1621 (not (eobp))) 1624 (setq orig-target-line (1+ (- orig-target-line
1622 (forward-line 1)) 1625 (count-lines (point-min) (point))))
1623 (while (and (not (eobp)) 1626 target-buf-count orig-target-line)
1624 (not (get-text-property (point) 'ibuffer-summary))) 1627 (while (and (not (eobp))
1625 (let ((result 1628 (not (get-text-property (point) 'ibuffer-summary)))
1626 (if (buffer-live-p (ibuffer-current-buffer)) 1629 (let ((result
1627 (save-excursion 1630 (if (buffer-live-p (ibuffer-current-buffer))
1628 (funcall function 1631 (save-excursion
1629 (ibuffer-current-buffer) 1632 (funcall function
1630 (ibuffer-current-mark) 1633 (ibuffer-current-buffer)
1631 (line-beginning-position) 1634 (ibuffer-current-mark)))
1632 (1+ (line-end-position)))) 1635 ;; Kill the line if the buffer is dead
1633 ;; Kill the line if the buffer is dead 1636 'kill)))
1634 'kill))) 1637 ;; A given mapping function should return:
1635 ;; A given mapping function should return: 1638 ;; `nil' if it chose not to affect the buffer
1636 ;; `nil' if it chose not to affect the buffer 1639 ;; `kill' means the remove line from the buffer list
1637 ;; `kill' means the remove line from the buffer list 1640 ;; `t' otherwise
1638 ;; `t' otherwise 1641 (incf ibuffer-map-lines-total)
1639 (incf ibuffer-map-lines-total) 1642 (cond ((null result)
1640 (cond ((null result) 1643 (forward-line 1))
1641 (forward-line 1)) 1644 ((eq result 'kill)
1642 ((eq result 'kill) 1645 (delete-region (line-beginning-position)
1643 (delete-region (line-beginning-position) 1646 (1+ (line-end-position)))
1644 (1+ (line-end-position))) 1647 (incf ibuffer-map-lines-count)
1645 (incf deleted-lines-count) 1648 (when (< ibuffer-map-lines-total
1646 (incf ibuffer-map-lines-count)) 1649 orig-target-line)
1647 (t 1650 (decf target-buf-count)))
1648 (incf ibuffer-map-lines-count) 1651 (t
1649 (forward-line 1))))) 1652 (incf ibuffer-map-lines-count)
1650 ibuffer-map-lines-count) 1653 (forward-line 1)))))
1654 ibuffer-map-lines-count)
1651 (progn 1655 (progn
1652 (setq buffer-read-only t) 1656 (setq buffer-read-only t)
1653 (unless nomodify 1657 (unless nomodify
1654 (set-buffer-modified-p nil)) 1658 (set-buffer-modified-p nil))
1655 (goto-line (- (1+ curline) deleted-lines-count)))))) 1659 (goto-char (point-min))
1660 (ibuffer-forward-line 0)
1661 (ibuffer-forward-line (1- target-buf-count))))))
1656 1662
1657 (defun ibuffer-get-marked-buffers () 1663 (defun ibuffer-get-marked-buffers ()
1658 "Return a list of buffer objects currently marked." 1664 "Return a list of buffer objects currently marked."
1659 (delq nil 1665 (delq nil
1660 (mapcar #'(lambda (e) 1666 (mapcar #'(lambda (e)
1661 (when (eq (cdr e) ibuffer-marked-char) 1667 (when (eq (cdr e) ibuffer-marked-char)
1662 (car e))) 1668 (car e)))
1663 (ibuffer-current-state-list)))) 1669 (ibuffer-current-state-list))))
1664 1670
1665 (defun ibuffer-current-state-list (&optional include-lines) 1671 (defun ibuffer-current-state-list ()
1666 "Return a list like (BUF . MARK) of all buffers in an ibuffer. 1672 "Return a list like (BUF . MARK) of all buffers in an ibuffer."
1667 If optional argument INCLUDE-LINES is non-nil, return a list like
1668 (BUF MARK BEGPOS)."
1669 (let ((ibuffer-current-state-list-tmp '())) 1673 (let ((ibuffer-current-state-list-tmp '()))
1670 ;; ah, if only we had closures. I bet this will mysteriously 1674 ;; ah, if only we had closures. I bet this will mysteriously
1671 ;; break later. Don't blame me. 1675 ;; break later. Don't blame me.
1672 (ibuffer-map-lines-nomodify 1676 (ibuffer-map-lines-nomodify
1673 (if include-lines 1677 #'(lambda (buf mark)
1674 #'(lambda (buf mark beg end) 1678 (when (buffer-live-p buf)
1675 (when (buffer-live-p buf) 1679 (push (cons buf mark) ibuffer-current-state-list-tmp))))
1676 (push (list buf mark beg) ibuffer-current-state-list-tmp)))
1677 #'(lambda (buf mark beg end)
1678 (when (buffer-live-p buf)
1679 (push (cons buf mark) ibuffer-current-state-list-tmp)))))
1680 (nreverse ibuffer-current-state-list-tmp))) 1680 (nreverse ibuffer-current-state-list-tmp)))
1681 1681
1682 (defun ibuffer-current-buffers-with-marks (curbufs) 1682 (defun ibuffer-current-buffers-with-marks (curbufs)
1683 "Return a list like (BUF . MARK) of all open buffers." 1683 "Return a list like (BUF . MARK) of all open buffers."
1684 (let ((bufs (ibuffer-current-state-list))) 1684 (let ((bufs (ibuffer-current-state-list)))
1865 1865
1866 This does not show new buffers; use `ibuffer-update' for that. 1866 This does not show new buffers; use `ibuffer-update' for that.
1867 1867
1868 If SILENT is non-`nil', do not generate progress messages." 1868 If SILENT is non-`nil', do not generate progress messages."
1869 (interactive) 1869 (interactive)
1870 (ibuffer-forward-line 0)
1870 (unless silent 1871 (unless silent
1871 (message "Redisplaying current buffer list...")) 1872 (message "Redisplaying current buffer list..."))
1872 (let ((blist (ibuffer-current-state-list))) 1873 (let ((blist (ibuffer-current-state-list)))
1873 (when (null blist) 1874 (when (null blist)
1874 (if (and (featurep 'ibuf-ext) 1875 (if (and (featurep 'ibuf-ext)
1876 (message "No buffers! (note: filtering in effect)") 1877 (message "No buffers! (note: filtering in effect)")
1877 (error "No buffers!"))) 1878 (error "No buffers!")))
1878 (ibuffer-insert-buffers-and-marks blist t) 1879 (ibuffer-insert-buffers-and-marks blist t)
1879 (ibuffer-update-mode-name) 1880 (ibuffer-update-mode-name)
1880 (unless silent 1881 (unless silent
1881 (message "Redisplaying current buffer list...done")))) 1882 (message "Redisplaying current buffer list...done"))
1883 (ibuffer-forward-line 0)))
1882 1884
1883 (defun ibuffer-update (arg &optional silent) 1885 (defun ibuffer-update (arg &optional silent)
1884 "Regenerate the list of all buffers. 1886 "Regenerate the list of all buffers.
1885 1887
1886 Display buffers whose name matches one of `ibuffer-maybe-show-predicates' 1888 Display buffers whose name matches one of `ibuffer-maybe-show-predicates'
1887 iff arg ARG is non-nil. 1889 iff arg ARG is non-nil.
1888 1890
1889 Do not display messages if SILENT is non-nil." 1891 Do not display messages if SILENT is non-nil."
1890 (interactive "P") 1892 (interactive "P")
1893 (ibuffer-forward-line 0)
1891 (let* ((bufs (buffer-list)) 1894 (let* ((bufs (buffer-list))
1892 (blist (ibuffer-filter-buffers 1895 (blist (ibuffer-filter-buffers
1893 (current-buffer) 1896 (current-buffer)
1894 (if (and 1897 (if (and
1895 (cadr bufs) 1898 (cadr bufs)