heredoc should be customizable on text left of <<

Bug #568178 reported by Yary H on 2010-04-22
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
nXhtml
Medium
Unassigned

Bug Description

Wishlist item: mumamo-heredoc-modes works well to a point. However when dealing with a large legacy codebase of shell scripts, it is also useful to be able to customize the submodes based on what is left of the "<<" heredoc marker.

Emacs shell-mode will insert "END" after typing << , so we have many files that say
#!/bin/ksh
(shell code here)

perl << END
(perl code here)
END

(shell code here)

sql_shell << END
(sql here)
END

(shell code here)

It would be helpful to have mumamo-heredoc-modes be a regular expression matching the entire heredoc definition line. Current entries could be anchored at the end of the line by adding " *$" to the end, and then new user-specified entries can be written to match the interpreter specified before the heredoc, anchored with a "^ *" at the start.

Thanks for considering this idea

lborgman (lennart-borgman) wrote :

Hi Yary,

An excellent idea, please try the new beta 2.07 I just uploaded to the repository.

Changed in nxhtml:
importance: Undecided → Medium
status: New → In Progress
Yary H (spam-launchpad) wrote :

Works, thanks!

Now I've found another heredoc related issue, an edge case.

Both shell scripts and perl allow code after the heredoc, on the same line.

Shell example (bteq is the Teredata sql shell)-

bteq <<EOF | grep '\\$'| read start_dt_ya start_dt end_dt_ya end_dt
-- SQL code here
select '$',start_date- '1 year', start_date ....
EOF

Perl example-
print SOCKET <<HTML or warn "Cannot write to socket: $!";
<input type="text">html continues...
HTML

In both those cases, the mumamo heredoc modes don't detect the heredoc closer, because it is looking for the entire line.

Also, both ksh, bash (all shells?) and perl allow quoted strings as the heredoc terminator, here's perl's documentation:

  The terminating string may be either an identifier (a word), or some quoted text. An unquoted identifier works like double quotes. There may not be a space between the << and the identifier, unless the identifier is explicitly quoted. (If you put a space it will be treated as a null identifier, which is valid, and matches the first empty line.)

shell example:
cat<<'foo bar'
foo
bar
foobar
foo bar

So, it seems the bit that detects the heredoc terminator needs a little polishing

Thanks for your help

lborgman (lennart-borgman) wrote :

Yes, it needs some polishing! Thanks for the explanations. I will look into it.

lborgman (lennart-borgman) wrote :

Hi Yary, please try the new beta 2.07.

Changed in nxhtml:
status: In Progress → Fix Committed
lborgman (lennart-borgman) wrote :

I have released version 2.08 with those changes now. I am closing this since I believe it is fixed. Please tell me if it is not.

Changed in nxhtml:
status: Fix Committed → Fix Released
Yary H (spam-launchpad) wrote :

yay, that much works, but now there's a fontification oddity. Check out the attached file with sh-heredoc-mumamo

The last bit of shell is fontified as if it is all inside a shell heredoc- it's like the heredoc continues on from the HTML section. Another oddity which I'm having a hard time reproducing is that shell code after a heredoc will look good except for when I'm editing it (when the point is inside the region), then it is fontified all in heredoc- when point is outside region, it looks good! You may or may not see it with this example.

lborgman (lennart-borgman) wrote :

Thanks Yary, but I can't reproduce those problems. Can you please give me a more precise way to see it? The best is if you start in a fresh Emacs with just nXhtml added, ie from

   M-x emacs-Q-nxhtml

Changed in nxhtml:
status: Fix Released → In Progress
Yary H (spam-launchpad) wrote :

 M-x emacs-Q-nxhtml - great function for debugging! I run that, and in the *scratch* buffer of the new window I eval this:

  (require 'mumamo-fun)
  (add-to-list 'auto-mode-alist '("\\.ksh$" . sh-heredoc-mumamo))

Then I open "foo.ksh" - it looks good at first open (and after a "revert-buffer").

Then I move the point (using down arrow key) to the line that says <a href="#"> and let it sit there a couple seconds

Then I move the point (using down arrow key) to the last line, and wait another second. Then the last chunk turns all yellow, instead of the pretty multi-color keyword/string coloring.

It seems to be something about the idle processing, since it isn't instant.

Yary H (spam-launchpad) wrote :

Ps. behavior happens with this slightly simplified file as well, it doesn't need anything extra after the heredoc marker:

# Test heredoc
echo "Does this look good?"

cat <<HTML
<a href="#">
HTML

# How is this fontified?
echo "Hello, world!"

lborgman (lennart-borgman) wrote :

Thanks for the examples, Yary.

I have tried to make a fix for this. It might look a little bit odd, but I think it is good enough for now. (And making it better is hard.)

Could you please try beta 2.09 that I just uploaded?

Changed in nxhtml:
status: In Progress → Fix Committed
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers