Subject: bug#13634: 24.2; trailing whitespace in calendar (enhancement)

From: Arun Persaud <[email-masked]>
Date: Wed, 06 Feb 2013 10:43:35 -0800

On 02/06/2013 08:41 AM, Bastien wrote:
> Hi Arun,
> 
> Arun Persaud <[email-masked]> writes:
> 
>> I like to show trailing white spaces in my buffers using
>>
>> (setq-default show-trailing-whitespace t)
>>
>> in my .emacs file. Since I have this enabled, I noticed
>> that the calendar (M-x calendar) has a lot of empty white space at the
>> end of the line. It would be nice if those could be removed before
>> displaying the calendar.
> 
> Can you make a patch for this?  It should be small enough so that we
> can apply it quickly.
> 
> Thanks,
> 

Here is a simple patch that seems to run on my computer, but I never
really looked at the calendar code before, so I'm not sure if this is
the right way of doing this.

The patch calls delete-trailing-whitespace for the current line when
advancing a line (via calendar-ensure-newline) and also removes the
whitespace for the last line when inserting a month into the buffer.
Removing the trailing whitespace doesn't seem to mess up the formatting,
since calendar-insert-at-column seems to be used when adding text which
fills the line with spaces in case it's needed before adding the text.

cheers
	
Arun
--- calendar.el	2013-02-06 10:28:54.679401343 -0800
+++ calendar.el.new	2013-02-06 10:28:25.738455568 -0800
@@ -1417,6 +1417,7 @@
 
 (defun calendar-ensure-newline ()
   "Move to the next line, adding a newline if necessary."
+  (delete-trailing-whitespace  (line-beginning-position) (line-end-position) )
   (or (zerop (forward-line 1))
       (insert "\n")))
 
@@ -1499,7 +1500,8 @@
                 (/= day last))
        (calendar-ensure-newline)
        (setq day (1+ day))              ; first day of next week
-       (calendar-insert-at-column indent calendar-intermonth-text trunc)))))
+       (calendar-insert-at-column indent calendar-intermonth-text trunc)))
+   (delete-trailing-whitespace  (line-beginning-position) (line-end-position))))
 
 (defun calendar-redraw ()
   "Redraw the calendar display, if `calendar-buffer' is live."