Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension .mjs is not recognized as javascript. #3230

Open
Lonniebiz opened this issue Jul 6, 2022 · 11 comments
Open

Extension .mjs is not recognized as javascript. #3230

Lonniebiz opened this issue Jul 6, 2022 · 11 comments

Comments

@Lonniebiz
Copy link

Lonniebiz commented Jul 6, 2022

Geany 1.37.1
Debian 11

Please associate the extension .mjs with javascript. When I open a mjs file, that contains javascript, the syntax highlighting I expect doesn't occur.

Furthermore, I see no way, within Geany's settings to create this association for future times that I open a .mjs file.

Lastly, at the bottom of the screen, where is says "Filetype: None", clicking that doesn't allow you to manually set the file type. I find this fact very non-intuitive.

@elextr
Copy link
Member

elextr commented Jul 6, 2022

See the manual

@Lonniebiz
Copy link
Author

Lonniebiz commented Jul 7, 2022

  1. I changed line 44 of of filetype_extensions.conf to:
    Javascript=*.js;*.mjs;
  2. Saved the file
  3. Closed Geany
  4. Re-Launched Geany
  5. Opened a file with a .mjs file extension

Still, the .mjs file is not receiving Javascript highlighting. @elextr

@elextr
Copy link
Member

elextr commented Jul 7, 2022

Also uncomment the [section header] line above.

@Lonniebiz
Copy link
Author

Lonniebiz commented Jul 7, 2022

@elextr Thank you. That worked, but the purpose of my bug report remains; I hope Geany will add .mjs as a default extension, so other JS developers don't have to endure any inconvenience regarding .mjs files.

Additionally, when a user changes a Filetype, for an extension Geany doesn't recognize via Document > Set Filetype, a very nice automation would be for Geany to prompt the user: "Would you like Geany to always open .mjs files as the JavaScript filetype?"

Lastly, on the information bar, at the bottom of Geany, I find it very un-intitive that you cannot just click filetype: none as a shortcut for achieving the same thing that Document > Set Filetype achieves.

These enhancements are certainly not a necessity, but I know they'll be appreciated by newcomers.

@elextr
Copy link
Member

elextr commented Jul 7, 2022

I hope Geany will add .mjs as a default extension, so other JS developers don't have to endure any inconvenience regarding .mjs files.

I'm sure if "somebody"1 made a pull request it wouldn't be a problem, so long as .mjs doesn't clash with anything else.

And any of the other enhancements could be accepted, but again "somebody" has to do it. Especially to explain how the "Would you like Geany to always open .mjs files as the JavaScript filetype?" would be extendable to anything else, having it hard coded seems weird if .mjs is in the filetype.extensions file.

Footnotes

  1. somebody in quotes is a project idiom for "not necessarily you, but almost certainly not me" :-)

@Lonniebiz
Copy link
Author

Lonniebiz commented Jul 7, 2022

I'm using a concrete example to explain an abstraction. I'm not suggesting to hard code .mjs specifically (other than I'm suggesting to make it a default).

Instead, I'm suggesting that any time a Geany user encounters "Filetype: None", that after they set that file type using Document > Set Filetype (for example), that Geany takes note of what ever that extension is, and asks the user "Would you always like to associate files with the extension ".???" with "the format you've just specified".

When a graphical user interface is complete, there's rarely a need to read a manual. If you want to do something to a thing, you right-click on that thing, and it shows you a list of "all you can do" with the thing that was right-clicked. You can intuitively discover anything you want to do and the application asks you if you want it to remember any preference the first time you do it. This is ideal, but I realize that is a whole lot of work to get it to that stage. I'm merely suggesting things that go that direction. @elextr

@Lonniebiz
Copy link
Author

Lonniebiz commented Jul 7, 2022

I'm not familiar with this code base, I'm not sure which file to modify to add .mjs as an extension for javascript.

Would it be line 144 here? :
https://github.com/geany/geany/blob/master/src/filetypes.c

Maybe you could add a line under that line that says:
FT_INIT( MJS, JAVASCRIPT, "Javascript", NULL, SOURCE_FILE, SCRIPT );

But, I can confirm this: people that use Node.js and ecmascript modules, must use the extension .mjs and not js for those modules. I call it Michael Jackson Script for fun, but here is the real reason:
https://stackoverflow.com/questions/57492546/what-is-the-difference-between-js-and-mjs-files

@brewmanz
Copy link

brewmanz commented Jul 11, 2022

See the manual

This is an unhelpful comment; pointing to a sample tutorial would be better. The manual seems geared to help those already familiar with the system, and those already understanding the nuances between Filetype definitions, Custom filetypes, Special file.filetypes, and Filetype extensions.
I am currently trying to add .awk extension to look like .pl, and having problems. I've created entry [Extensions] + Awk=*.awk; in filetype_extensions.conf, created in ~/.config/geany/filedefs. Also a filetypes.awk there, copied from /usr/shared/geany/filedefs/filetypes.perl and changing perl & pl to awk but ... not working.

@elextr
Copy link
Member

elextr commented Jul 11, 2022

I'm not sure which file to modify to add .mjs as an extension for javascript.

The system filetype_extensions.conf that you edited locally.

This is an unhelpful comment; pointing to a sample tutorial would be better.

If someone wrote one they could put it on the wiki and post a link here.

I am currently trying to add .awk extension to look like .pl, and having problems. I've created entry [Extensions] + Awk=*.awk; in filetype_extensions.conf, created in ~/.config/geany/filedefs. Also a filetypes.awk there, copied from /usr/shared/geany/filedefs/filetypes.perl and changing perl & pl to awk but ... not working.

If you want awk to be treated like perl, can't you just add *.awk to the perl line?

@brewmanz
Copy link

brewmanz commented Jul 11, 2022

If you want awk to be treated like perl, can't you just add *.awk to the perl line?

Different extension, different keywords. I can change ~/.config/geany/filetype_extensions.conf line Perl=*.pl;*.perl;*.pm;*.agi;*.pod; to Perl=*.pl;*.perl;*.pm;*.agi;*.pod;*.awk; which formats as a perl file, which I suppose is a start. But why doesn't it work with:

  • an alternative additional line of Awk=*.awk;
  • together with a file ~/.config/geany/filetypes.awk that's cloned from /usr/shared/geany/filedefs/filetypes.perl with changes
--- /home/xxx/.config/geany/filedefs/filetypes.awk
+++ /home/xxx/.config/geany/filedefs/filetypes.perl
@@ -1,4 +1,3 @@
-# 2020-07-11 copied from /usr/shared/geany/filedefs/filetypes.perl
 # For complete documentation of this file, please see Geany's main documentation
 [styling]
 # Edit these in the colorscheme .conf file instead
@@ -53,20 +52,17 @@
 format=string_2
 
 [keywords]
-# add awk keywords before NULL __FILE__
-primary=function switch case break default CONVFMT FIELDWIDTHS FS IGNORECASE OFMT OFS ORS RS SUBSEP ARGC ARGV ARGIND ENVIRON ERRNO FILENAME FNR NF NR RLENGTH RSTART RT PROCINFO NULL __FILE__ __LINE__ __PACKAGE__ __SUB__ __DATA__ __END__ AUTOLOAD BEGIN CORE DESTROY END EQ GE GT INIT LE LT NE CHECK abs accept alarm and atan2 bind binmode bless caller chdir chmod chomp chop chown chr chroot close closedir cmp connect continue cos crypt dbmclose dbmopen default defined delete die do dump each else elsif endgrent endhostent endnetent endprotoent endpwent endservent eof eq eval exec exists exit exp fcntl fileno flock for foreach fork format formline ge getc getgrent getgrgid getgrnam gethostbyaddr gethostbyname gethostent getlogin getnetbyaddr getnetbyname getnetent getpeername getpgrp getppid getpriority getprotobyname getprotobynumber getprotoent getpwent getpwnam getpwuid getservbyname getservbyport getservent getsockname getsockopt given glob gmtime goto grep gt hex if index int ioctl join keys kill last lc lcfirst le length link listen local localtime lock log lstat lt m map mkdir msgctl msgget msgrcv msgsnd my ne next no not oct open opendir or ord our pack package pipe pop pos print printf prototype push q qq qr quotemeta qu qw qx rand read readdir readline readlink readpipe recv redo ref rename require reset return reverse rewinddir rindex rmdir s say scalar seek seekdir select semctl semget semop send setgrent sethostent setnetent setpgrp setpriority setprotoent setpwent setservent setsockopt shift shmctl shmget shmread shmwrite shutdown sin sleep socket socketpair sort splice split sprintf sqrt srand stat state study sub substr symlink syscall sysopen sysread sysseek system syswrite tell telldir tie tied time times tr truncate uc ucfirst umask undef unless unlink unpack unshift untie until use utime values vec wait waitpid wantarray warn when while write x xor y
+primary=NULL __FILE__ __LINE__ __PACKAGE__ __SUB__ __DATA__ __END__ AUTOLOAD BEGIN CORE DESTROY END EQ GE GT INIT LE LT NE CHECK abs accept alarm and atan2 bind binmode bless caller chdir chmod chomp chop chown chr chroot close closedir cmp connect continue cos crypt dbmclose dbmopen default defined delete die do dump each else elsif endgrent endhostent endnetent endprotoent endpwent endservent eof eq eval exec exists exit exp fcntl fileno flock for foreach fork format formline ge getc getgrent getgrgid getgrnam gethostbyaddr gethostbyname gethostent getlogin getnetbyaddr getnetbyname getnetent getpeername getpgrp getppid getpriority getprotobyname getprotobynumber getprotoent getpwent getpwnam getpwuid getservbyname getservbyport getservent getsockname getsockopt given glob gmtime goto grep gt hex if index int ioctl join keys kill last lc lcfirst le length link listen local localtime lock log lstat lt m map mkdir msgctl msgget msgrcv msgsnd my ne next no not oct open opendir or ord our pack package pipe pop pos print printf prototype push q qq qr quotemeta qu qw qx rand read readdir readline readlink readpipe recv redo ref rename require reset return reverse rewinddir rindex rmdir s say scalar seek seekdir select semctl semget semop send setgrent sethostent setnetent setpgrp setpriority setprotoent setpwent setservent setsockopt shift shmctl shmget shmread shmwrite shutdown sin sleep socket socketpair sort splice split sprintf sqrt srand stat state study sub substr symlink syscall sysopen sysread sysseek system syswrite tell telldir tie tied time times tr truncate uc ucfirst umask undef unless unlink unpack unshift untie until use utime values vec wait waitpid wantarray warn when while write x xor y
 
 [lexer_properties]
 styling.within.preprocessor=1
 
 [settings]
 # default extension used when saving files
-extension=awk
-#extension=pl
+extension=pl
 
 # MIME type
-mime_type=application/x-awk
-#mime_type=application/x-perl
+mime_type=application/x-perl
 
 # the following characters are these which a "word" can contains, see documentation
 #wordchars=_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
@@ -98,14 +94,12 @@
 # %e will be replaced by the filename without extension
 # (use only one of it at one time)
 
-compiler=awk -f %f
-#compiler=perl -cw "%f"
+compiler=perl -cw "%f"
 
 # alternatively use perlcc
 #compiler=perlcc -o "%e" "%f"
 
-run_cmd=awk -f %f
-#run_cmd=perl "%f"
+run_cmd=perl "%f"
 
 # Parse syntax check error messages and warnings, examples:
 # syntax error at test.pl line 7, near "{
 

@elextr
Copy link
Member

elextr commented Jul 11, 2022

different keywords.

Ok, fair enough, but since its nothing to do with the OP about .mjs please make another issue rather than hijacking this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants