It's obvious that it's better not to have trailing whitespace in files.
I'm not against adding a section in the developer's manual for this but
I doubt it will make any difference in practice. If people use editors
which are prone to trailing whitespace, that is not going to change.
Personally, I do NOT consider this a problem. I would like to remove
whitespace after non-empty lines, but I don't really care much about
whitespace-only lines.
Here is one of the big situations when I like trailing spaces:
def hello():$
print 'hi'$
$
print 'bye'$
To me, it's annoying to have the cursor jump back to column 0 when
scrolling down through the function. I think that is the only situation
where I get annoyed with my emacs settings of deleting trailing whitespace.
Thanks,
Jason
If you tell me how to make emacs do that, I'll stop being a repeat
offender (just as I no longer -- I think -- submit patches with tabs
in!)
John
Here is what is in my .emacs:
;; trailing whitespace
(setq-default show-trailing-whitespace t)
;(add-hook 'before-save-hook 'delete-trailing-whitespace)
The first line shows trailing whitespace in a big bold red font. The
second automatically deletes it. I commented out the second line because:
1. It was adding too much noise to existing patches (deleting all
trailing whitespace in a file)
2. the annoying issue with an all-whitespace line, pointed out in my
message above.
Thanks,
jason
Putting the above (emacs code + discussion) in the Developer's Guide
would be very useful.
William
> Thanks,
>
> jason
>
>
> --
> To post to this group, send an email to sage-...@googlegroups.com
> To unsubscribe from this group, send an email to
> sage-devel+...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/sage-devel
> URL: http://www.sagemath.org
>
--
William Stein
Professor of Mathematics
University of Washington
http://wstein.org
Patches to my .emacs are more than welcome! :)
Jason
Based on the no-tabs-in-Sage-code experience, the only way to have any
kind of actual effect is to add a tool to the merge or doctest scripts
so that new trailing whitespace causes an error.
(Working on Sage has taught me that only automated tools work; asking
people to remember something or behave a certain way always fails. :)
It seems like no one wants to have an epic break-all-patches-in-trac
patch that removes all the trailing whitespace in the Sage library --
and, some people like some trailing whitespace, so perhaps we should
also add just a warning to the sage-merge script (or whatever release
managers use to add patches)?
Dan
--
--- Dan Drake
----- http://mathsci.kaist.ac.kr/~drake
-------
+1 to this policy ! WE are trying to do that in the sage-combinat project.
Systematically remove all trailing whitespaces creates a lot of conflicts in
the patch queue so I'm strongly against it.
Cheers,
Florent
Tim Daly
The following would be easy for me to do: remove all *newly added*
trailing whitespace from patches (except on lines consisting only of
spaces). Basically, s/^\(+.*[^ ]\) *$/\1/ in the patches.
I think that would be a good idea, although if you're just running that
through sed, the exact patches applied would be different from the ones
on the trac server, which would cause some confusion.
The point is that I don't like warnings. There used to be time when not
having a ticket number in the commit message created a warning in my
merger script. This meant I had to complain on a lot of tickets about
the commit message. Eventually, people were asking, "why doesn't your
script automatically add the ticket number?". Since then, that's how
things are done in the merger script. No warnings, just automatically
(and silently) make the change.
Jeroen.
I'm well aware of that... Mercurial has some extension as well... Or else, I
can rewrite a script to do it... The question is:
- is there a simple and robust way to *transparently* do that for all the 50
contributors of the sage-combinat project, while keeping the compatibility of
the queue with the two/three past versions of sage ???
Each time there has been such a big change within sage, the effect has been
that:
1) the coordinators of the sage-combinat project (ie Nicolas and myself) lost
two days of work, rebasing the queue and ensuring compatibility with two or
three version of sage and solving various contributors problems;
2) each contributors lost upto several hours;
3) but most important to us: as a consequence we lost some contributors.
Nicolas is on vacation now but I'm pretty sure he will agree with me.
Of course any *working* solution is mostly welcome !!!
Cheers,
Florent
If you're using Emacs 24 you can install quarter-plane.el through the GNU ELPA. This uses picture mode to automatically insert spaces so that you can move anywhere in the full quarter plane.
I tried it and I don't like it, but YMMV. One problem is that it pollutes the undo space, but I can't believe you can't work around that somehow by fiddling with `buffer-undo-list'.
Looking at quarter-plane mode, it seems like the magic that you want could probably be done by rebinding your movement keys to `picture-move-up' and `picture-move-down' or writing similar functions.
Personally, I detest trailing whitespace—I can't abide hitting C-e and it not going where I expect. It also doesn't bother me to have the cursor jump back to column 0, but it might help that I have the whole line highlighted.
-Ivan
Even better, it could be done by a trac pluging itself (at the moment
when it matters most), not the patchbot, which may or may not run
later.
>
>
>> The point is that I don't like warnings. There used to be time when not
>> having a ticket number in the commit message created a warning in my
>> merger script. This meant I had to complain on a lot of tickets about
>> the commit message.
>
> Me neither. Of course it would be better if the complaints were
> generated automagically...
> Reasonable commit messages (and btw. also patch filenames and
> attachment comments) are valuable *before* a ticket gets merged as
> well; the latter two are more or less irrelevant after a ticket has
> been merged, since they don't appear in a release, or as soon as
> you've imported a patch. (The filenames of course appear in your
> Mercurial patch queues and shell history, so *are* pretty relevant
> during development.)
For me having ticket numbers (and comments) in a patch are
*incredibly* important *after* a ticket has been merged. I would say
they are way more important after than before merge. Typically,
when I see some code that is suspect in Sage, I use "hg blame" to see
what patch last modified that code, I look at the commit message of
the patch to see the ticket number, then look at the relevant page on
trac.
>> Eventually, people were asking, "why doesn't your
>> script automatically add the ticket number?". Since then, that's how
>> things are done in the merger script. No warnings, just automatically
>> (and silently) make the change.
>
> Well, as far as I know invalid commit messages (or more precisely ones
> lacking a ticket number) never created merge conflicts.
But they make future development work on Sage (especially for me) much harder.
Automatically adding them on merge is a great solution.
> Also, if a developer doesn't get warnings (and nobody else complains),
> he/she's unlikely to change his/her practice, so they're of
> educational value as well. ;-)
>
>
> -leif
>
No ! It is not ! It is a non trivial and painful task for the sage-combinat
community. Please remember that
- we have a queue of approximatively 250 patches !
- we have approximatively 40/50 contributors, not all of them are using the
last version of sage, only a few of them are mercurial advanced users.
So please tell me how trivially solve the following problem:
We want a robust way to *transparently* do remove whitespace in code and
patches for all the 50 contributors of the sage-combinat project, while
keeping the compatibility of the queue with the two/three past versions of
sage ???
As I already said, each time you did such a change:
1) the coordinators of the sage-combinat project (ie Nicolas and myself) lost
two days of work, rebasing the queue and ensuring compatibility with two or
three version of sage and solving various contributors problems;
2) each contributors lost upto several hours;
3) but most important to us: as a consequence we lost some contributors.
Of course any *working* solution is mostly welcome !!!
Cheers,
Florent
Please re-read carefully the statement of the problem ! How do you ensure
compatibility with the *former* version of sage (the one where the space in
the source files are still there) ?
Cheers,
Florent
My last answer was a little rude or at least very short. Since Nicolas is on
vacation I'm the only sage-combinat coordinator keeping an eye here this week.
Anyway, we are both currently completely buried under the teaching load (eg:
for me 15 hours new lectures since Monday). So please don't feel offended by
this short answer. I had the impression that you where ready to jump on the
script and that we Nicolas and myself will suffer shortly...
On Wed, Oct 26, 2011 at 02:07:54AM -0700, Keshav Kini wrote:
> Ah, I'm sorry, I misunderstood your question. Yes, that is a problem. I see
> no way around it in general. The only way to mitigate this is to try to
> avoid changing files that sage-combinat is working on.
That's precisely what I was more or less asking... At least, please don't do
it without having a green light from our side.
> But I doubt that Sage developers want to commit to such a promise, unless
> sage-combinat wants to take ownership of parts of Sage... and certainly your
> objection applies to any broad changes to the Sage codebase. But what leif
> (I think) and I were trying to say is that at least this change he mentioned
> would be a lot easier to handle than other large-scale changes (such as,
> say, python3 migration changes which will eventually happen).
If you want some example of what has been painful in the past, here they
are. Note: I don't intend any offense against the responsible of those
changes, I'm just asking for coordination; Trivial change for you are not
trivial at all for us:
- Automatic replacement of
EXAMPLES::$
sage:
by
EXAMPLES::$
$
sage:
- tab replaced by spaces;
- bunch of typos corrections.
> If I understand correctly, sage-combinat is an project which develops
> extensions of Sage which periodically (when sage-combinat feels a
> particular ticket is ready for review?) gets included into Sage itself.
You understand correctly with "periodically" meaning when we feel that things
are stable/tested enough. So this is some kind of coordinated development and
pre-review process. Low level changes (eg: in the category system) are shaken
and tested before inclusion. Being able to do that in a relatively large scale
is quite efficient. Moreover we often need those code for research...
> The standard way to do such a thing with Mercurial is to maintain a separate
> clone of the Sage repository (or a separate branch within the Sage
> repository), and merge changes from mainstream Sage into that repo every
> time Sage releases a new version. This way you don't need to muck about with
> rebasing multiple patch files etc., and pulling from the sage-combinat repo
> back into the mainstream Sage repo is relatively painless. In particular,
> I've never heard of anyone long-term sharing a patch queue repository and
> using it for development - that sounds really painful to me!
This is going definitely off topic...
First of all, I'm not a revision control expert ! Maybe there is a better
solution. We didn't saw it with Nicolas after *quite* some thinking. If a
better working and robust solution come up, we will more than gladly adopt it.
But we won't redo this thinking again, unless we become completely stuck.
We used (with CVS) this kind of workflow when working with MuPAD. I wasn't
satisfactory. The problem is that when you are working in parallel on a stable
and a more experimental modifications of the same files, it is hard to unfold
the change sets to submit it after. More precisely, suppose that on a single
file I'm doing in sequence four modifications 1 2 3 4, I want to submit
modification 1 and 3 to trac while keeping 2 and 4 for a forthcoming
ticket. Of course change 2 and 3 must commute. With mercurial queue, this is
just moving line in the series file. With branches, you will end up with a
sequence of changeset. You need to extract those you want at the end. In my
experience and understanding, you have to follow a very strong discipline to
annotate every changeset committed with the information needed to select it at
the end. With patches, you can do it along the way commuting and folding
patches.
Anyway, the fact is that
- our development workflow more or less work (except during those big
changes);
- actually I feel that it work too well, so that we are abusing it ;-) They
are plenty of patch in the queue which are 1 or 2 hours work away from
being merged into sage and stay here for several months.
As I said, maybe we did it wrong, but it took quite some thinking to setup
properly the workflow and to write the tools (the "sage -combinat" script). I
don't see it changing unless an expert propose us streamlined solution. We
spend already quite a time explaining the workflow to contributors. I don't
think we will do any change to it, unless we are sure that the new workflow is
much easier and robust than the previous one.
> (pre-posting edit: People in the IRC channel #mercurial on freenode said
> that they have heard of this workstyle but find it "quite painful" too...)
>
> However, sadly, Sage does not really properly use Mercurial in a nice way,
> i.e. nobody touches our repository except the release manager, and there
> are scripts to handle all of that, which only expect to be merging patches
> from trac tickets and not doing anything else. So it may be a bit difficult
> to implement a nicer way for sage-combinat to collaborate with Sage, at
> least at the moment...
>
> (As you may know, I am a very junior Sage developer so take what I say with
> a grain of salt, please :) )
Don't worry ! I'm not a revision control expert either. And thanks for your
suggestions.
Cheers,
Florent
PS: there are plenty of whitespaces at the end of the lines of your message ;-)
[whitespace]
What do other major open source projects (e.g., the Linux kernel) do
regarding whitespace and patches? What are their policies?
William
Interesting solution. But please. The barrier and standards for
contributions are already high enough. Let's not insist on a
contributor using emacs (as much as I personally like it), or
configuring their editor for such an issue. Let's just view not having
spaces on nonempty lines as good style and leave it at that. And let's
not insist that people who spent a lot of their time to program a patch
be rejected, for example if their editor happened to put a space when it
automatically wrapped/filled a documentation line. I think if I was a
new contributor, with limited time, who had just spent a lot of time
learning python, mercurial, queues, trac, docstrings, rest, doctests,
and everything else we demand for a good patch, if I got rejected
because of an extra space at the end of a line, I may just throw my
hands up in the air and give up.
>
> By the way, there is also a third-party Mercurial extension which bugs
> you when you try to commit (or qnew/qrefresh, I imagine) trailing
> whitespace. We could... ship this with the built-in Mercurial, for what
> it's worth, but I think the above solution (hooking into trac) is better.
>
> Again, sorry for wasting your time with such a trivial matter. I didn't
> expect the thread to grow so huge! :)
I agree. As Florent pointed out, the maintenance burden would be huge.
Rejections for such an inconsequential bike-shedding issue that is
just a matter of taste are a huge turn-off for a new developer. The
benefits are practically nil, as I see it. I think the linux policy is
sane---if you happen to be editing a line and remove the trailing
whitespace, good for you. But let's leave it at that.
Sorry, I don't mean to be mean. I just think there are far more
important things that would help Sage, and I don't see any positives to
rejecting patches by people for such an issue.
Thanks,
Jason
That's kind of a silly question. Of course it's possible, that's why it's emacs. ;-)
I was playing around with something like this yesterday. The following advice for next-line (and the same for previous-line) gets at least part of the way there, but I found I don't really like it personally.
(defadvice next-line (around empty-line-fix
(&optional arg try-vscroll)
activate)
(let ((goal (or goal-column
(if (< (current-column) (current-indentation))
(current-column)
(current-indentation)))))
;; Delete trailing whitespace from the current line before moving
(delete-trailing-whitespace (line-beginning-position)
(line-end-position))
;; Move the lines
ad-do-it
;; Insert spaces as needed
(when (and (> (- goal (current-column)) 0)
(not (string-match "\\S "
(buffer-substring-no-properties
(line-beginning-position)
(line-end-position)))))
(insert-char ?\ (- goal (current-column))))))
-Ivan
+1
Ideally, when you upload a patch it would do a bunch of checks and
present to you a "fixed" file with the option of downloading it or
replacing the original file right there.
>>> The point is that I don't like warnings. There used to be time when not
>>> having a ticket number in the commit message created a warning in my
>>> merger script. This meant I had to complain on a lot of tickets about
>>> the commit message.
>>
>> Me neither. Of course it would be better if the complaints were
>> generated automagically...
>> Reasonable commit messages (and btw. also patch filenames and
>> attachment comments) are valuable *before* a ticket gets merged as
>> well; the latter two are more or less irrelevant after a ticket has
>> been merged, since they don't appear in a release, or as soon as
>> you've imported a patch. (The filenames of course appear in your
>> Mercurial patch queues and shell history, so *are* pretty relevant
>> during development.)
>
> For me having ticket numbers (and comments) in a patch are
> *incredibly* important *after* a ticket has been merged. I would say
> they are way more important after than before merge. Typically,
> when I see some code that is suspect in Sage, I use "hg blame" to see
> what patch last modified that code, I look at the commit message of
> the patch to see the ticket number, then look at the relevant page on
> trac.
My thoughts exactly.
>>> Eventually, people were asking, "why doesn't your
>>> script automatically add the ticket number?". Since then, that's how
>>> things are done in the merger script. No warnings, just automatically
>>> (and silently) make the change.
>>
>> Well, as far as I know invalid commit messages (or more precisely ones
>> lacking a ticket number) never created merge conflicts.
>
> But they make future development work on Sage (especially for me) much harder.
> Automatically adding them on merge is a great solution.
Yep.
As far as whitespace, the difficulty here is merge conflicts with
upstream. Right now the sage-combinat queue is the major player here;
what if we stripped trailing whitespace in the merger script for
everything outside the combinat directory (and also ship the
whitespace-intelligent hg plugin with Sage as a convenience).
If we can't come up with a solution that's low-maintenance on
developers (including the sage-combinat folks), release managers, and
contributors (read, no rejecting patches due to trailing whitespace)
then it's probably better to just leave it as a non-enforced
suggestion.
- Robert
An even better option would be a "submit patch to trac" command, which
could take as set of patches from your queue, clean them up,
optionally run a bunch of tests, and upload them (updating the
description to the current set and any dependencies).
- Robert
Sure ! I wasn't saying that we shouldn't have corrected those. I wasn't saying
either that we shouldn't correct typos. I just said that I remember loosing
quite a few hours ensuring by cutting a big patch boob chunk by chunk that the
combinat queue remain applicable with or without this correction.
Cheers,
Florent
I just tried to do this for sage-4.8.alpha1 and the problem is reviewer
patches. If a ticket has a "main" patch adding new trailing whitespace
and a "reviewer" ticket changing those lines, then removing new trailing
whitespace from patches creates conflicts.