patchGNU nano - Patches: patch #9719, support filetype detection via...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

patch #9719: support filetype detection via Emacs/Vim modeline magic

Submitter:  easyaspi314 <easyaspi314>
Submitted:  Sat 10 Nov 2018 10:33:45 PM UTC
   
 
Priority:  3 - Low Status:  Wont Do
Privacy:  Public Assigned to:  None
Open/Closed:  Closed Release:  None

Sun 06 Oct 2019 10:06:41 AM UTC, comment #2: 

Recognizing extensionless C++ files by their modeline has been added (though a 'header' command) to git, commit 2698a2ba.

If there are any other files on a regular distro that are not recognized from their filename, feel free to suggest additional 'header' regexes.

Benno Schulenberg <bens>
Group administrator
Sun 11 Nov 2018 12:28:15 PM UTC, comment #1: 

First, if your nano does not recognize the files in /usr/include/c++/*/, it means you have disabled libmagic support.

Second, disabling libmagic support is an understandable measure, but... instead of adding a whole new 'modeline' command, why not use the 'header' command to recognize the modeline?  Is it really necessary to override the file extension recognition?  Do you have any files where the extension does not match the content?

Benno Schulenberg <bens>
Group administrator
Sat 10 Nov 2018 10:33:45 PM UTC, original submission:  

Two syntax-related patches in one day.

If you have ever opened one of the headers in /usr/include/c++/*/, you will likely notice two things.

First of all, nano has no idea what the heck the file is.

Second of all, you see a weird comment on the first line like so:


// -*- C++ -*-


That is a modeline magic comment for Emacs, telling it what language the file is in, despite not knowing the extension.

Vim also has its own syntax that does a similar thing.

Modeline magic comments look like this:


// -*- C++ -*-


or


/* vim: set filetype=cpp: */


or


# -*- mode: sh -*- vim: ft=sh


Before this, nano would not be able to detect those files, and would use the default highlighting.

Now, nano will read the first line to try and autodetect them.

Without much work, most filetypes are now recognized by their magic because they match the name, but for those which don't match their syntax name, or have multiple names such as C++, there is the new modeline keyword:


syntax c "..."
modeline "\<C(\+\+|pp)?\>"


The comparison is case-insensitive.

Now, open up a header in /usr/include/c++/*/ and admire the colors.

This takes priority over file extensions.

This was surprisingly easy to implement once I got the regex right.

easyaspi314 <easyaspi314>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bens (Posted a comment)
  • -email is unavailable- added by easyaspi314 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-07-04 bens Open/ClosedOpen Closed
    2019-10-06 bens StatusNone Wont Do
    2018-11-11 bens SummarySupport filetype detection via Emacs/Vim modeline magic support filetype detection via Emacs/Vim modeline magic
    2018-11-11 bens Priority5 - Normal 3 - Low
    2018-11-10 easyaspi314 Attached File- Added 0001-Support-filetype-detection-via-Vim-Emacs-modeline-ma.patch, #45401

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code