-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Description
Background
While participating in https://community.notepad-plus-plus.org/topic/22819/select-language-by-name-and-not-by-extension , two issues came up that are related, but that I'll document as separate issues or requests. (I think the fixes will be in different sections of code, though maybe they can actually be fixed simultaneously)
When a file with no extension is opened in Notepad++, then the program will run some first line heuristics, and files that start with unix-style shebang lines (like #!/bin/bash or #!/usr/bin/env perl) will switch to the language indicated by the shebang (Unix shell script or Perl source file in those two examples); or if it starts with <?xml version="1.0" encoding="UTF-8"?>, it will be interpreted as XML.
Problem
This heuristic works as expected when the default language (Settings > Preferences > New File > Default Language) is set to None (Normal Text). However, if the default language is set to anything else, then the heuristic is not applied and the default language is always selected. The expected behavior would be that the same heuristic is applied to files with no extension, whether the default language is set to None or to something else.
Reproduce
- Create the file
<?xml version="1.0" encoding="UTF-8"?>
<blah></endblah>
- Save as
test - Close the file
- Settings > Preferences > New File > Default Language > Ada (or other language)
- Open the file and look at the selected Language-menu (or the Language in the Status Bar)
- ACTUAL BEHAVIOR: it opens as Ada file (follows the Default Language setting)
- EXPECTED BEHAVIOR: it opens as an XML file, just like the it would if Default Language were None (Normal Text)
Other
user @franco-otaola determined the order of priority in https://community.notepad-plus-plus.org/post/75877:
- extension of the file
- default language
- first line e.g. #!/bin/bash
In both of our expectations, this is not the desired behavior. We would expect that if the heuristic (shebang or ) applies to a default language of None (Normal Text) that it would also apply the same heuristic -- so in the ordered list, the priorities of #2 and #3 would swap, so it would go in order of extension, shebang/xml, then default.
(Obviously, I would expect that a file created with File > New would keep the default file type, even if the first line typed were a shebang or xml declaration. And that if the user manually set Language, it should keep that. It's just when reading a new file that has no extension that I would expect the order of priority in the decision process to change compared to what it is now.)
Debug Info
Notepad++ v8.3.3 (64-bit)
Build time : Mar 13 2022 - 17:20:02
Path : C:\usr\local\apps\npp\npp.8.3.3.portable.x64\notepad++.exe
Command Line : -multiInst
Admin mode : OFF
Local Conf mode : ON
Cloud Config : OFF
OS Name : Windows 10 Enterprise (64-bit)
OS Version : 2009
OS Build : 19042.1586
Current ANSI codepage : 1252
Plugins : mimeTools.dll NppConverter.dll NppExport.dll