diff options
| author | Chong Yidong | 2007-06-04 20:33:46 +0000 |
|---|---|---|
| committer | Chong Yidong | 2007-06-04 20:33:46 +0000 |
| commit | a1d155a4c1e041bbb80ee92acbf93a7bb34694e5 (patch) | |
| tree | ee1cef6cf6aa3fb4124689cfbacd03138046ccc7 | |
| parent | c6b98d9f2ec86cdc242692e5b777a3935745f8b6 (diff) | |
| download | emacs-a1d155a4c1e041bbb80ee92acbf93a7bb34694e5.tar.gz emacs-a1d155a4c1e041bbb80ee92acbf93a7bb34694e5.zip | |
(longlines-mode): Make longlines-auto-wrap buffer-local. Add hooks
unconditionally.
(longlines-auto-wrap): Toggle wrapping.
(longlines-after-change-function)
(longlines-post-command-function): Check longlines-auto-wrap.
| -rw-r--r-- | lisp/longlines.el | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/lisp/longlines.el b/lisp/longlines.el index e8ab4fbdd88..149f69c9f26 100644 --- a/lisp/longlines.el +++ b/lisp/longlines.el | |||
| @@ -110,6 +110,7 @@ are indicated with a symbol." | |||
| 110 | (add-hook 'change-major-mode-hook 'longlines-mode-off nil t) | 110 | (add-hook 'change-major-mode-hook 'longlines-mode-off nil t) |
| 111 | (add-hook 'before-revert-hook 'longlines-before-revert-hook nil t) | 111 | (add-hook 'before-revert-hook 'longlines-before-revert-hook nil t) |
| 112 | (make-local-variable 'buffer-substring-filters) | 112 | (make-local-variable 'buffer-substring-filters) |
| 113 | (make-local-variable 'longlines-auto-wrap) | ||
| 113 | (set (make-local-variable 'isearch-search-fun-function) | 114 | (set (make-local-variable 'isearch-search-fun-function) |
| 114 | 'longlines-search-function) | 115 | 'longlines-search-function) |
| 115 | (add-to-list 'buffer-substring-filters 'longlines-encode-string) | 116 | (add-to-list 'buffer-substring-filters 'longlines-encode-string) |
| @@ -149,12 +150,10 @@ are indicated with a symbol." | |||
| 149 | (add-to-list 'message-indent-citation-function | 150 | (add-to-list 'message-indent-citation-function |
| 150 | 'longlines-decode-region t))) | 151 | 'longlines-decode-region t))) |
| 151 | 152 | ||
| 153 | (add-hook 'after-change-functions 'longlines-after-change-function nil t) | ||
| 154 | (add-hook 'post-command-hook 'longlines-post-command-function nil t) | ||
| 152 | (when longlines-auto-wrap | 155 | (when longlines-auto-wrap |
| 153 | (auto-fill-mode 0) | 156 | (auto-fill-mode 0))) |
| 154 | (add-hook 'after-change-functions | ||
| 155 | 'longlines-after-change-function nil t) | ||
| 156 | (add-hook 'post-command-hook | ||
| 157 | 'longlines-post-command-function nil t))) | ||
| 158 | ;; Turn off longlines mode | 157 | ;; Turn off longlines mode |
| 159 | (setq buffer-file-format (delete 'longlines buffer-file-format)) | 158 | (setq buffer-file-format (delete 'longlines buffer-file-format)) |
| 160 | (if longlines-showing | 159 | (if longlines-showing |
| @@ -365,29 +364,27 @@ Hard newlines are left intact." | |||
| 365 | ;; Auto wrap | 364 | ;; Auto wrap |
| 366 | 365 | ||
| 367 | (defun longlines-auto-wrap (&optional arg) | 366 | (defun longlines-auto-wrap (&optional arg) |
| 368 | "Turn on automatic line wrapping, and wrap the entire buffer. | 367 | "Toggle automatic line wrapping. |
| 369 | With optional argument ARG, turn off line wrapping." | 368 | With optional argument ARG, turn on line wrapping if and only if ARG is positive. |
| 369 | If automatic line wrapping is turned on, wrap the entire buffer." | ||
| 370 | (interactive "P") | 370 | (interactive "P") |
| 371 | (remove-hook 'after-change-functions 'longlines-after-change-function t) | 371 | (setq arg (if arg |
| 372 | (remove-hook 'post-command-hook 'longlines-post-command-function t) | 372 | (> (prefix-numeric-value arg) 0) |
| 373 | (not longlines-auto-wrap))) | ||
| 373 | (if arg | 374 | (if arg |
| 374 | (progn (setq longlines-auto-wrap nil) | 375 | (let ((mod (buffer-modified-p))) |
| 375 | (message "Auto wrap disabled.")) | 376 | (setq longlines-auto-wrap t) |
| 376 | (setq longlines-auto-wrap t) | 377 | (longlines-wrap-region (point-min) (point-max)) |
| 377 | (add-hook 'after-change-functions | 378 | (set-buffer-modified-p mod) |
| 378 | 'longlines-after-change-function nil t) | 379 | (message "Auto wrap enabled.")) |
| 379 | (add-hook 'post-command-hook | 380 | (setq longlines-auto-wrap nil) |
| 380 | 'longlines-post-command-function nil t) | 381 | (message "Auto wrap disabled."))) |
| 381 | (let ((mod (buffer-modified-p))) | ||
| 382 | (longlines-wrap-region (point-min) (point-max)) | ||
| 383 | (set-buffer-modified-p mod)) | ||
| 384 | (message "Auto wrap enabled."))) | ||
| 385 | 382 | ||
| 386 | (defun longlines-after-change-function (beg end len) | 383 | (defun longlines-after-change-function (beg end len) |
| 387 | "Update `longlines-wrap-beg' and `longlines-wrap-end'. | 384 | "Update `longlines-wrap-beg' and `longlines-wrap-end'. |
| 388 | This is called by `after-change-functions' to keep track of the region | 385 | This is called by `after-change-functions' to keep track of the region |
| 389 | that has changed." | 386 | that has changed." |
| 390 | (unless undo-in-progress | 387 | (when (and longlines-auto-wrap (not undo-in-progress)) |
| 391 | (setq longlines-wrap-beg | 388 | (setq longlines-wrap-beg |
| 392 | (if longlines-wrap-beg (min longlines-wrap-beg beg) beg)) | 389 | (if longlines-wrap-beg (min longlines-wrap-beg beg) beg)) |
| 393 | (setq longlines-wrap-end | 390 | (setq longlines-wrap-end |
| @@ -396,7 +393,7 @@ that has changed." | |||
| 396 | (defun longlines-post-command-function () | 393 | (defun longlines-post-command-function () |
| 397 | "Perform line wrapping on the parts of the buffer that have changed. | 394 | "Perform line wrapping on the parts of the buffer that have changed. |
| 398 | This is called by `post-command-hook' after each command." | 395 | This is called by `post-command-hook' after each command." |
| 399 | (when longlines-wrap-beg | 396 | (when (and longlines-auto-wrap longlines-wrap-beg) |
| 400 | (if (or (eq this-command 'yank) | 397 | (if (or (eq this-command 'yank) |
| 401 | (eq this-command 'yank-pop)) | 398 | (eq this-command 'yank-pop)) |
| 402 | (longlines-decode-region (point) (mark t))) | 399 | (longlines-decode-region (point) (mark t))) |