* Auto-detect Guile in a text editor @ 2018-10-23 11:07 HiPhish 2018-10-23 11:36 ` Tkprom ` (2 more replies) 0 siblings, 3 replies; 5+ messages in thread From: HiPhish @ 2018-10-23 11:07 UTC (permalink / raw) To: guile-user Hello Schemers When I open a Scheme file (Neo)vim the file type is set to "scheme", but I would like to be able to detect that it is not just Scheme, but Guile Scheme. So far I have set up the editor to scan the first line for a shebang and if the word "guile" appears to set the file type to "scheme.guile": if getline(1) =~? '\v^#!.*[Gg]uile' let &filetype .= '.guile' endif If you are not familiar with Vim, the important part is the regex '^#!.*[Gg]uile'. This works OK, but is there a better way than adding a shebang or some other manual hing to the head of every script? How does Emacs do it? And while I'm at that topic, what is the proper way of writing a shebang when I don't know where Guile is installed to? For example, the Guile manual frequently uses #!/usr/local/bin/guile but what if I have Guile installed via Guix and it is somewhere in my Guix store? A common solution is to abuse env: #!/usr/bin/env guile But now I cannot pass arguments (like '-s') to Guile, because everything following the first space will be treated as one argument to 'env'. Is there a solution or am I just overthinking things? ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Auto-detect Guile in a text editor 2018-10-23 11:07 Auto-detect Guile in a text editor HiPhish @ 2018-10-23 11:36 ` Tkprom 2018-10-23 12:33 ` Tk 2018-10-23 12:58 ` Matt Wette 2018-11-13 14:45 ` Barry Fishman 2 siblings, 1 reply; 5+ messages in thread From: Tkprom @ 2018-10-23 11:36 UTC (permalink / raw) To: HiPhish; +Cc: guile-user@gnu.org On Tuesday, 23 October 2018 13:07, HiPhish <hiphish@posteo.de> wrote: > Hello Schemers > > When I open a Scheme file (Neo)vim the file type is set to "scheme", but I > would like to be able to detect that it is not just Scheme, but Guile Scheme. > So far I have set up the editor to scan the first line for a shebang and if > the word "guile" appears to set the file type to "scheme.guile": > > if getline(1) =~? '\v^#!.[Gg]uile' > let &filetype .= '.guile' > endif > If you are not familiar with Vim, the important part is the regex > '^#!.[Gg]uile'. This works OK, but is there a better way than adding ashebang or some other manual hing to the head of every script? How does Emacs > do it? > > And while I'm at that topic, what is the proper way of writing a shebang when > I don't know where Guile is installed to? For example, the Guile manual > frequently uses > > #!/usr/local/bin/guile > > but what if I have Guile installed via Guix and it is somewhere in my Guix > store? A common solution is to abuse env: > > #!/usr/bin/env guile > > But now I cannot pass arguments (like '-s') to Guile, because everything > following the first space will be treated as one argument to 'env'. Is there a > solution or am I just overthinking things? Hi, Maybe you could look into how Geiser does it in Emacs. As far as I know, Geiser is a de-facto Guile IDE for Emacs (http://www.nongnu.org/geiser/). Your approach will only work for the she-banged scripts. For anything else, I suppose there is going to be some guess-work involved. For example, often used Guile constructs are "define-module", #:use-module, use-modules ... they all usually appear at the top. Ditto "ice-9" . Scan top 20-50 lines for those keywords and there is a high probability the Scheme file is a Guile file if it contains any of those. About your second question: yes, that sucks! This is why i stopped using executable guile scripts and am now just doing: $ guile my-program.scm options to the program Perhaps someone else has a better solution. Hope this helps, Tk ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Auto-detect Guile in a text editor 2018-10-23 11:36 ` Tkprom @ 2018-10-23 12:33 ` Tk 0 siblings, 0 replies; 5+ messages in thread From: Tk @ 2018-10-23 12:33 UTC (permalink / raw) To: Tkprom; +Cc: guile-user@gnu.org, HiPhish ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ On Tuesday, 23 October 2018 13:36, Tkprom <tk.code@protonmail.com> wrote: > On Tuesday, 23 October 2018 13:07, HiPhish hiphish@posteo.de wrote: > > > Hello Schemers > > When I open a Scheme file (Neo)vim the file type is set to "scheme", but I > > would like to be able to detect that it is not just Scheme, but Guile Scheme. > > So far I have set up the editor to scan the first line for a shebang and if > > the word "guile" appears to set the file type to "scheme.guile": > > if getline(1) =~? '\v^#!.[Gg]uile' > > let &filetype .= '.guile' > > endif > > If you are not familiar with Vim, the important part is the regex > > '^#!.[Gg]uile'. This works OK, but is there a better way than adding ashebang or some other manual hing to the head of every script? How does Emacs > > do it? > > And while I'm at that topic, what is the proper way of writing a shebang when > > I don't know where Guile is installed to? For example, the Guile manual > > frequently uses > > #!/usr/local/bin/guile > > but what if I have Guile installed via Guix and it is somewhere in my Guix > > store? A common solution is to abuse env: > > #!/usr/bin/env guile > > But now I cannot pass arguments (like '-s') to Guile, because everything > > following the first space will be treated as one argument to 'env'. Is there a > > solution or am I just overthinking things? > > Hi, > > Maybe you could look into how Geiser does it in Emacs. As far as I know, Geiser is a de-facto Guile IDE for Emacs (http://www.nongnu.org/geiser/). > > Your approach will only work for the she-banged scripts. For anything else, I suppose there is going to be some guess-work involved. For example, often used Guile constructs are "define-module", #:use-module, use-modules ... they all usually appear at the top. Ditto "ice-9" . Scan top 20-50 lines for those keywords and there is a high probability the Scheme file is a Guile file if it contains any of those. > > About your second question: yes, that sucks! This is why i stopped using executable guile scripts and am now just doing: > > $ guile my-program.scm options to the program > > Perhaps someone else has a better solution. > > Hope this helps, > > Tk One more thing: since the current attempts at standardisation of Scheme language are pushing for uniformity among different implementations (I know, I know, it may never happen), perhaps scanning for dialect-specific usage is not the nicest approach. I prefer the approach where leaving a comment marker somewhere would activate the required functionality. For example, in Emacs, you could write something like, ; -*- mode: Scheme; eval: (whatever-minor-guile-mode-is-used 1); -*- . ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Auto-detect Guile in a text editor 2018-10-23 11:07 Auto-detect Guile in a text editor HiPhish 2018-10-23 11:36 ` Tkprom @ 2018-10-23 12:58 ` Matt Wette 2018-11-13 14:45 ` Barry Fishman 2 siblings, 0 replies; 5+ messages in thread From: Matt Wette @ 2018-10-23 12:58 UTC (permalink / raw) To: guile-user On 10/23/18 4:07 AM, HiPhish wrote: > And while I'm at that topic, what is the proper way of writing a shebang when > I don't know where Guile is installed to? For example, the Guile manual > frequently uses > > #!/usr/local/bin/guile > > but what if I have Guile installed via Guix and it is somewhere in my Guix > store? A common solution is to abuse env: > > #!/usr/bin/env guile > > But now I cannot pass arguments (like '-s') to Guile, because everything > following the first space will be treated as one argument to 'env'. Is there a > solution or am I just overthinking things? > Sometime I need to do shell processing, so I use #!/bin/sh exec guile $0 "$@" !# (define foo 1) ... ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Auto-detect Guile in a text editor 2018-10-23 11:07 Auto-detect Guile in a text editor HiPhish 2018-10-23 11:36 ` Tkprom 2018-10-23 12:58 ` Matt Wette @ 2018-11-13 14:45 ` Barry Fishman 2 siblings, 0 replies; 5+ messages in thread From: Barry Fishman @ 2018-11-13 14:45 UTC (permalink / raw) To: guile-user On 2018-10-23 13:07:33 +02, HiPhish wrote: > Hello Schemers > > When I open a Scheme file (Neo)vim the file type is set to "scheme", but I > would like to be able to detect that it is not just Scheme, but Guile Scheme. > So far I have set up the editor to scan the first line for a shebang and if > the word "guile" appears to set the file type to "scheme.guile": > > if getline(1) =~? '\v^#!.*[Gg]uile' > let &filetype .= '.guile' > endif > > If you are not familiar with Vim, the important part is the regex > '^#!.*[Gg]uile'. This works OK, but is there a better way than adding a > shebang or some other manual hing to the head of every script? How does Emacs > do it? Vim like Emacs recognizes modelines in the file. I start guile scripts with: #! /bin/sh ## -*- mode: scheme; coding: utf-8 -*- ## Time-stamp: <2018-09-14 08:43:42 barry> exec ${GUILE:-guile} -e main -s $0 ${1+"$@"} !# -- Barry Fishman ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-11-13 14:45 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-10-23 11:07 Auto-detect Guile in a text editor HiPhish 2018-10-23 11:36 ` Tkprom 2018-10-23 12:33 ` Tk 2018-10-23 12:58 ` Matt Wette 2018-11-13 14:45 ` Barry Fishman
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).