diff options
| author | Gerd Moellmann | 2000-04-19 19:07:56 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2000-04-19 19:07:56 +0000 |
| commit | c16c855b51578fb79f0323593a8a9e4c86327258 (patch) | |
| tree | 24cd976ad71004057c229ddb5c70611ed9effb62 | |
| parent | 586b375962fa25da41109d6d55206bf85e1acc81 (diff) | |
| download | emacs-c16c855b51578fb79f0323593a8a9e4c86327258.tar.gz emacs-c16c855b51578fb79f0323593a8a9e4c86327258.zip | |
(count-screen-lines): New function.
(shrink-window-if-larger-than-buffer): Use count-screen-lines
instead of window-buffer-height.
| -rw-r--r-- | lisp/window.el | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/lisp/window.el b/lisp/window.el index e5639a50827..6f7e730bad4 100644 --- a/lisp/window.el +++ b/lisp/window.el | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | ;;; window.el --- GNU Emacs window commands aside from those written in C. | 1 | ;;; window.el --- GNU Emacs window commands aside from those written in C. |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1985, 1989, 1992, 1993, 1994 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1985, 1989, 1992, 1993, 1994, 2000 |
| 4 | ;; Free Software Foundation, Inc. | ||
| 4 | 5 | ||
| 5 | ;; Maintainer: FSF | 6 | ;; Maintainer: FSF |
| 6 | 7 | ||
| @@ -258,6 +259,42 @@ to the window's right, if any. No arg means split equally." | |||
| 258 | nil | 259 | nil |
| 259 | window)))))) | 260 | window)))))) |
| 260 | 261 | ||
| 262 | (defun count-screen-lines (&optional beg end count-final-newline window) | ||
| 263 | "Return the number of screen lines in the region. | ||
| 264 | The number of screen lines may be different from the number of actual lines, | ||
| 265 | due to line breaking, display table, etc. | ||
| 266 | |||
| 267 | Optional arguments BEG and END default to `point-min' and `point-max' | ||
| 268 | respectively. | ||
| 269 | |||
| 270 | If region ends with a newline, ignore it unless optinal third argument | ||
| 271 | COUNT-FINAL-NEWLINE is non-nil. | ||
| 272 | |||
| 273 | The optional fourth argument WINDOW specifies the window used for obtaining | ||
| 274 | parameters such as width, horizontal scrolling, and so on. The default is | ||
| 275 | to use the selected window's parameters. | ||
| 276 | |||
| 277 | Like `vertical-motion', `count-screen-lines' always uses the current buffer, | ||
| 278 | regardless of which buffer is displayed in WINDOW. This makes possible to use | ||
| 279 | `count-screen-lines' in any buffer, whether or not it is currently displayed | ||
| 280 | in some window." | ||
| 281 | (unless beg | ||
| 282 | (setq beg (point-min))) | ||
| 283 | (unless end | ||
| 284 | (setq end (point-max))) | ||
| 285 | (if (= beg end) | ||
| 286 | 0 | ||
| 287 | (save-excursion | ||
| 288 | (save-restriction | ||
| 289 | (widen) | ||
| 290 | (narrow-to-region (min beg end) | ||
| 291 | (if (and (not count-final-newline) | ||
| 292 | (= ?\n (char-before (max beg end)))) | ||
| 293 | (1- (max beg end)) | ||
| 294 | (max beg end))) | ||
| 295 | (goto-char (point-min)) | ||
| 296 | (1+ (vertical-motion (buffer-size) window)))))) | ||
| 297 | |||
| 261 | (defun shrink-window-if-larger-than-buffer (&optional window) | 298 | (defun shrink-window-if-larger-than-buffer (&optional window) |
| 262 | "Shrink the WINDOW to be as small as possible to display its contents. | 299 | "Shrink the WINDOW to be as small as possible to display its contents. |
| 263 | Do not shrink to less than `window-min-height' lines. | 300 | Do not shrink to less than `window-min-height' lines. |
| @@ -280,7 +317,10 @@ or if the window is the only window of its frame." | |||
| 280 | (or (not mini) | 317 | (or (not mini) |
| 281 | (< (nth 3 edges) (nth 1 (window-edges mini))) | 318 | (< (nth 3 edges) (nth 1 (window-edges mini))) |
| 282 | (> (nth 1 edges) (cdr (assq 'menu-bar-lines params))))) | 319 | (> (nth 1 edges) (cdr (assq 'menu-bar-lines params))))) |
| 283 | (let ((text-height (window-buffer-height window)) | 320 | ;; `count-screen-lines' always works on the current buffer, so |
| 321 | ;; make sure it is the buffer displayed by WINDOW. | ||
| 322 | (let ((text-height (with-current-buffer (window-buffer window) | ||
| 323 | (count-screen-lines))) | ||
| 284 | (window-height (window-height))) | 324 | (window-height (window-height))) |
| 285 | ;; Don't try to redisplay with the cursor at the end | 325 | ;; Don't try to redisplay with the cursor at the end |
| 286 | ;; on its own line--that would force a scroll and spoil things. | 326 | ;; on its own line--that would force a scroll and spoil things. |