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

Use modeline (file variables) settings in source code preview #269

Open
smithwinston opened this issue Jan 10, 2025 · 0 comments
Open

Use modeline (file variables) settings in source code preview #269

smithwinston opened this issue Jan 10, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@smithwinston
Copy link

Problem
When previewing source files it appears to be using a default tab size, but anything that uses a non-default setting isn't rendered properly (this is also an issue with telescope and fzf-lua in neovim+lazy).

Feature
If a source file has a modeline (vim terminology) or file-variables (emacs terminology), then use that for the tab settings for example by extracting tab-width (emacs file variables) or ts (vim modeline).

If the file type if specified, for example using the mode (emacs) or ft (vim) then use that rather than the file extension (for example, I use the C mode/filetype for .ragel files because I don't have a mode for ragel, but it mostly looks like C).

Examples
An example of a Makefile with both emacs file variables and a vim modeline is as follows:

# -*- mode: Makefile; tab-width: 8 -*-
# vim: ts=8:noet

CC      = gcc
CFLAGS  = -Wall -g 

OBJECTS = main.o utils.o
TARGET  = myprogram

$(TARGET): $(OBJECTS)
        $(CC) $(CFLAGS) -o $(TARGET) $(OBJECTS)

%.o: %.c
        $(CC) $(CFLAGS) -c $< -o $@

Additional context
There are a few projects around that use regular expressions to parse out the file variables/modelines from the first 5-10 lines of each file, here's a fairly comprehensive looking example:

https://github.com/github-linguist/linguist/blob/main/lib/linguist/strategy/modeline.rb

@smithwinston smithwinston added the enhancement New feature or request label Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant