Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!oliveb!intelca!mipos3!nate From: nate@mipos3.intel.com (Nate Hess) Newsgroups: comp.emacs Subject: Bug in center-region + Fix Keywords: center-region Message-ID: <2433@mipos3.intel.com> Date: 23 Jun 88 17:26:10 GMT Reply-To: nate@mipos3.intel.com (Nate Hess) Organization: Intel Corporation, Santa Clara, CA Lines: 50 I've found a bug in the center-region function of GNU Emacs. (We're running 18.51 here.) A pseudo-lossage description of how to repeat the bug (after typing emacs -q from the command line): E n t e r SPC p a s s w o r d SPC f o l l o w e d SPC b y SPC < C R > SPC t o SPC e x i t . ESC x c e n t e r - l RET RET RET RET RET RET RET RET RET RET RET b a c k SPC i n SPC 5 RET w o o d s t o c k RET C-r C-q LFD C-q LFD ESC ESC > ESC x c e n t e r - r RET C-h l The 'back in 5' line centers, but the 'woodstock' line doesn't. Here's the new center-region function I wrote that fixes this bug: (defun center-region (from to) "Center each line starting in the region. See center-line for more info." (interactive "r") (if (> from to) (let ((tem to)) (setq to from from tem))) (save-excursion (goto-char from) ; ; Basically, the bug stemmed from the fact that the end of the ; region is fixed at the beginning of the while loop, and characters ; are added to center lines properly, but the variable 'to' ; representing the end of the region does not reflect the new ; effective region each time 'center-line' is called. ; (let (number-of-ws-chars original-number-of-ws-chars) (while (< (point) to) (setq original-number-of-ws-chars (count-indenting-ws-chars)) (center-line) (setq number-of-ws-chars (count-indenting-ws-chars)) (setq to (+ to (- number-of-ws-chars original-number-of-ws-chars))) (forward-line 1)))) ) ;center-region I mailed this into bug-gnu-emacs, but never saw it on the mailing list... If you can see any obvious improvements I could make in the code, drop me a line. Happy Centering, --woodstock -- "How did you get your mind to tilt like your hat?" ...!{decwrl|hplabs!oliveb|pur-ee|qantel|amd}!intelca!mipos3!nate: nate@mipos3.intel.com ATT : (408) 765-4309