Make Pollen compatible with new module-suffixes
facility
#34
Closed
opened 10 years ago by notio
·
40 comments
Loading…
Reference in New Issue
There is no content yet.
Delete Branch '%!s(<nil>)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
I believe this is a Racket issue rather than a Pollen issue, but perhaps I'm missing something, or there is a config/pref that could be added to the Pollen guide.
This instruction, in quick.scrbl...
... appears to be broken using a clean install of the 64-bit Mac OS X Racket distribution (racket-6.1.1-x86_64-macosx.dmg).
It appears this version of DrRacket is unable to save a file without appending the .rkt extension. In the Save dialog (or the Save Definitions As... dialog, or the Save Other > Save Definitions As Text... dialog) I can delete the .rkt extension in the dialog but it saves with the .rkt extension applied anyway.
If, in the Save dialog, I remove the .rkt extension and the file exists it will ask if I want to overwrite it, which I do, and it thinks it does, but the file as shown by the Finder actually has the .rkt extension (correctly overwritten).
The summary here is that a browser pointed at the project server cannot just reload the page, because that page hasn't changed. The "hello.txt.pp.rkt" page has changed.
This only worked initially because when I first started the tutorial I manually changed the filename in the Finder, thinking, "Oh, I forgot to delete the default extension in the Save dialog, I'll just change the name." So then there was a page at http://localhost:8080/hello.txt but it never changes when saving via DrRacket...
If I had a solution I'd make a pull request against the docs, but I'm currently stumped. Pointers? Take it to Racket?
I also reported this just now using the DrRacket "Submit Bug Report..." function in the Help menu.
Sorry about the trouble. This problem has been reported once before, as issue #14, which also has some tips on working around it.
A question was also submitted to the Racket list at that time, though the author of DrRacket was not able to account for it either.
Unfortunately I’ve never been able to reproduce it on my copies of OS X. Nor has it surfaced repeatedly by people using Pollen. Which makes me wonder if there’s some third ingredient responsible for this bug.
Anyhow, if the Save boxes in DrRacket are not cooperating, you can just save the file with any name you want and change it in the Finder (either directly or through the Get Info box). Or start the file in any text editor (e.g., Sublime Text) and then open it in DrRacket. Or you can just create & edit your files in a text editor other than DrRacket.
FYI, I'm having this problem as well. I'm just touching the files in Terminal to create them with the right names before editing them in DrRacket. I'm on 10.8.5 — that might have something to do with it. Pollen is awesome.
Coincidentally, earlier today I pushed a workaround (
7bfd403023
) for this issue (and issue https://github.com/mbutterick/pollen/issues/14).Instead of naming source files with a double extension like
index.html.pm
, you can optionally use the escape character_
for the inner extension. Thus your source file can be namedindex_html.pm
, but it will still output toindex.html
.You can also change the escape character on a per-project basis. This is noted in the new docs under “File formats.” (use
raco pkg update --update-deps pollen
to get the patch & new docs).I never determined why this was happening in the first place (indeed, I’ve never been able to reproduce it on my own machine). But, since there are at least some combinations of software that object to double extensions, better to just have an approved way of handling it.
OK — updated all in raco pkg.
The behavior of DrRacket would seem to be unchanged when trying to save a Pollen file with
.pmd
despite escaping the inner extension. It seems DrRacket is examining the end of the filename string each time a character is changed and when it the end of the string doesn't match a known valid extension, it checks theHide extension
box and appends a hidden.rkt
.Editing a new file, the save dialog opens with the "Hide extension" option unchecked and the filename field empty. Lets say we want to name the file
test.html.pmd
. As soon ast
is typed, thehide extension
field is auto-checked (and a hidden.rkt
extension is appended). Upon enteringtest.h
the box unchecks itself (and the extension is removed). Attest.ht
it checks itself again. Attest.htm
it unchecks, and stays unchecked attest.html
. Then, eithertest.html!
ortest.html.
will cause the box to check itself again (and append a hidden.rkt
). The process repeats as DrRacket apparently examines the end of the filename string, looking for a valid final extension. If it doesn't find one it likes, it forces the checkbox on and appends.rkt
.DrRacket accepts
.pp
and.pm
as valid extensions, leaves theHide extension
box cleared and does not append.rkt
. That is not the case for.pmd
. Whether or not escaping the innerhtml
with!
.Thank you for the report. I think I need to try this myself on a clean OS X install. I wonder if OS X perhaps intuits the approved file types from the Spotlight index or something similar. When I try to save with a
pmd
extension in DrRacket, I get the dialog box shown below. However, if I try extensions likepmdd
ormpd
, I get the same behavior you describe. So there seems to be a sense in which my system has relented on the validity ofpmd
.One more diganostic. The approved file types are viewable in OS X by running this command:
When I search in this file for
.pmd
I discover that it’s been registered on my system as a Pagemaker file extension (probably by some Adobe software). That might explain why the results on this bug are erratic: people who happen to have.pmd
already registered by some other program don’t have a problem.Do you find any reference to
.pmd
in this file?Still suggests that testing on a clean system will be instructive.
My launchregister dump doesn't seem to have anything for pmd.
Hm, then it seems likely that Pollen should be registering its source-file types during installation on OS X. (Looks like the preferred procedure is to use
lsregister
, a process described here.).This seems, however, like it might be the tip of a larger-than-Pollen iceberg, because Racket is designed to create new languages (that are not Racket and thus probably don’t use the
.rkt
etc. extensions). So file-extension registration is potentially an endemic issue. @rfindler, do you want to weigh in before I blunder ahead?Sorry I don't have any good advice. @mflatt has some good ideas I bet.
Let it be known that I am a novice and on most days I'm lucky if I can find my parentheses with both hands. That said, perhaps there could be an option added to the 'Warnings' or 'General' preference panels to disable extension hiding and the save panel's filename extension safety checks. There's already one that disables the changed format warning. (Toggling it doesn't alter this aspect of extension checking.) Those who want to use unregistered extensions can probably tolerate having
.rkt
in the save dialog when saving standard files.Alternatively, might it be possible to use the Open With contextual menu in the Finder to associate targeted extensions with DrRacket? I tried setting it permanently (in the Other... subdialog, check 'Always Open With'); it didn't change the save panel's behavior, or produce anything in lsregister. Perhaps that functionality requires an existing entry in the lsregister db....
Well, the deeper problem is that DrRacket, because it’s a cross-platform app, delegates the Save dialog to the underlying OS. So if there’s an OS-specific wart — as there is here — there’s not much on the Racket end of things that can (or should) be done to laser it.
I’m not sure that a fix can be rolled into
raco pkg install
anyhow. I’d bet a dollar that changing thelsregister
database requires superuser access (meaning, a password). (I’ll try it and make sure.) But if so, thenraco pkg install
would stop being a fully automated process, and that is kapu.I think it would be wiser for me to just put a little script in the package that will add Pollen’s source extensions to OS X if you want them / need them. And if that script needs a password, nobody will be bothered.
I’ve just pushed an update with a file called
tools/os x/register-pollen-source-extensions.app
.This is a tiny app that holds the Pollen file extensions to OS X. The idea is that you register this app with OS X, and thereby its file extensions, and after that they will be recognized throughout the system (including the Save dialog in DrRacket).Get the Pollen update (
raco pkg update --update-deps pollen
)Determine the path to the
lsregister
tool on your system. On mine it’slsregister
to register the file extensions with this Terminal command:Restart.
Let me know if that helped.
Sorry about the lumpy fix but once I know it works for someone other than myself, I can add a shell script that will smooth things out.
I found this SE post helpful in putting this together.
I just tried installing Pollen on a clean OS X Yosemite machine. Good news and weird news. The good news is that the fix seems to work. The weird news is that it seems to auto-execute when the
pollen
package is installed — no messing withlsregister
necessary. I classify that as “weird” news rather than “especially good” because I didn’t plan for that to happen & not clear why it does. However, the new DrRacket recognizes all the Pollen file extensions. So … lacking any evidentiary basis to keep this issue open, it is now closed.Running DrRacket 6.2.1 (64 bit) on an up-to-date Yosemite, I continue to have this issue and it's pretty annoying. Basically if any keypress results in the last four characters not being equal to
.rkt
, the "Hide Extension" checkbox is immediately selected and the.rkt
extension appended invisibly. (This is true even if I type outhello.txt.pp
, uncheck Hide Extension which changes it tohello.txt.pp.rkt
and then highlight the.rkt
extension and delete it with a single keystroke.)I first updated pollen using
raco pkg
and rebooted. When that did not work I removed it and reinstalled it (also usingraco
), and rebooted. Finally I ran thelsregister
command manually, and rebooted, still no luck.Note, at this point if I do "Get Info" on a file
hello.txt.pp
, the dialog lists it as "Kind: Pollen preprocessor source file".Barring a fix, the only workarounds involve either a) saving the file with .rkt and somehow renaming it afterwards, or b) creating the file (e.g.
touch hello.txt.pp
) and then opening it.When you “ran the
lsregister
command,” you mean you ran it like so — with theregister-pollen-source-extensions.app
as the argument?This is interesting to me because the only way this line will show up is from the little database of file extensions packaged with
register-pollen-source-extensions.app
.If you change the extension of the file to
ptree
and do Get Info, what does it say?Yep, exactly so.
Yes, that’s what I was thinking. If I change the extension to
.ptree
Get Info says “Pollen pagetree source file”.Strange. That proves that the Pollen file extensions are indeed getting registered (which is good) but I would expect that to make them valid across OS X (DrRacket & elsewhere).
OTOH I notice now that other OS X programs don’t have the “Hide Extension” box that DrRacket does. So maybe DrRacket (= a cross-platform program) is making some broad assumptions about file naming that aren’t entirely accurate on OS X.
I’ll take a look at Windows Racket and see how it compares.
Racket Central Command has advised me that a centralized facility for handling file extensions is in the offing, so patience is counseled.
In the meantime, a dumb-but-effective workaround would be to change your Pollen file extensions to those that DrRacket already recognizes, like
rkt
,rktd
, andss
. You would do this by adding aconfig
submodule to yourdirectory-require.rkt
like so:Then instead of
filename.html.pm
you would name your markup files e.g.,filename.html.rkt
and preprocessor files e.g.styles.css.rktd
.Apparently this centralized facility has been implemented in the development version of Racket. I need to do some work to make Pollen compatible with it. But assuming it works, that will be the best solution. I’ll leave this issue open as a reminder.
BTW I changed the default escape-extension character from
!
to_
after noticing that this is a convention already used in Racket (for instance, withdep
andzo
files).Pollen is now compatible with the current Racket development build, which includes support for language-specified file extensions, which in this case are
pp
pm
pmd
ptree
andp
.This feature will probably take a while to show up in an official stable release, so if you want to use it, you’ll need to build Racket from GitHub source (= no big deal) or download a snapshot build (= easy).
Thank you to @mflatt for making this possible.
I just installed the latest DrRacket (version 6.8) and trying to go through the pollen tutorial in Mac OS X I am having the same problems described in this old issue. Was it ever fixed? If so, is there a single place with instructions on how to modify the settings of DrRacket or the settings of OS X to force DrRacket to save files with extensions other than .rkt?
What do you get if you run this program in DrRacket?
I get this
'(#"rkt" #"pm" #"pmd" #"pp" #"ptree" #"scm" #"scrbl" #"ss")
OK, that means the Pollen file extensions are recognized. Do you have the same file-saving problem with
scm
orscrbl
files (also on that list) or are the problems restricted to the Pollen extensions (pp
pm
et al)I just tried the scm and scrbl extensions and they both work. When I type either of them the box to hide extension unchecks itself, but that doesn't happen with the Pollen extensions.
And this is what version of Mac OS?
It's Sierra, 10.12.1
@rfindler / @mflatt — any intuitions about this before I start spelunking? Pollen is adding filename suffixes with the
module-suffixes
property ininfo.rkt
.These suffixes are being reported correctly by(get-module-suffixes)
:But there is nevertheless a difference in behavior between the “native” extensions (
rkt
scrbl
ss
) and ones added viamodule-suffixes
.The fact that this problem disappeared for 18 months and has now resurfaced makes me wonder if something related to the handling of suffixes has changed recently ... ? Hence my question about intuitions.
PS I am also using Sierra and have not had this problem. The fact that this issue is not consistently reproducible has been noted before. But that was all prior to the addition of
module-suffixes
in Aug 2015.It may be instructive to put a printf here:
https://github.com/racket/gui/blob/master/gui-lib/framework/private/finder.rkt#L46
and here:
https://github.com/racket/gui/blob/master/gui-lib/framework/private/finder.rkt#L71
to see what the actual arguments being passed to
get-file
andput-file
are in order to figure out if this is a bug in the framework/drracket or in some lower layer.I am also having this issue. What's more, I was able to save as .pp the first few times I tried. Now I can't get it to work. I'm not sure what changed.
What version of Sierra?
BTW I’m using Sierra 10.12.3 and can’t reproduce this problem. @freefrancisco said he’s using Sierra 10.12.1.
I just upgraded my Sierra to 10.12.3 and the problem went away!
Interesting -- I'm using 10.12.4 beta!
This seems to show that this is not a Racket or Pollen problem, but rather Mac OS. If the bug in Sierra 10.12.4 persists to the release version, I will revisit the issue then (as I will assumedly be able to reproduce it too)
Just wanted to report back and say that I haven't been experiencing this issue anymore (I'm still on 12.4 beta, but I did upgrade to DrRacket v6.9, which I think may have reset some settings?).
Now that I'm a bit more experienced with Pollen, I also wanted to say a huge thank you for this incredible tool! As a teacher, I've been using it to write pretty assignments for my students and loving it. Hoping to use it for a personal website this summer as well. Thanks so much!