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

Associate *.[1-9] file extensions with Text #4258

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions lib/linguist/heuristics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def self.call(blob, candidates)

@heuristics.each do |heuristic|
if heuristic.matches?(blob.name, candidates)
return Array(heuristic.call(data))
return Array(heuristic.call(data, blob.name))
end
end

Expand Down Expand Up @@ -58,6 +58,9 @@ def self.parse_rule(named_patterns, rule)
return And.new(rules)
elsif !rule['pattern'].nil?
return self.to_regex(rule['pattern'])
elsif !rule['filename_pattern'].nil?
pat = self.to_regex(rule['filename_pattern'])
return FilenamePattern.new(pat)
elsif !rule['negative_pattern'].nil?
pat = self.to_regex(rule['negative_pattern'])
return NegativePattern.new(pat)
Expand Down Expand Up @@ -98,9 +101,13 @@ def matches?(filename, candidates)
end

# Internal: Perform the heuristic
def call(data)
def call(data, filename)
matched = @rules.find do |rule|
rule['pattern'].match(data)
if rule['filename_pattern']
rule['filename_pattern'].match(filename)
else
rule['pattern'].match(data)
end
end
if !matched.nil?
languages = matched['language']
Expand All @@ -114,15 +121,13 @@ def call(data)
end

class And

def initialize(pats)
@pats = pats
end

def match(input)
return !@pats.any? { |pat| !pat.match(input) }
end

end

class AlwaysMatch
Expand All @@ -131,15 +136,23 @@ def match(input)
end
end

class NegativePattern
class FilenamePattern
def initialize(pat)
@pat = pat
end

def match(input)
return @pat.match(input)
end
end

class NegativePattern
def initialize(pat)
@pat = pat
end

def match(input)
return !@pat.match(input)
end

end
end
14 changes: 14 additions & 0 deletions lib/linguist/heuristics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# regular expression (with union).
# and - An and block merges multiple rules and checks that all of
# of them must match.
# filename_pattern - Same as pattern, but tests filenames instead of content.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this for? It doesn't appear to be used anywhere.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that. This was an addition to the heuristics format to accommodate Text files which ended with version numbers (stuff like GPL-2.2 and stuff). I must've overlooked the heuristic that used it when resolving merge conflicts, but on second thought, I'm not sure it's even needed...

I recall it was @pchaigno's suggestion. @pchaigno, do we still need this? If not, we can simplify the format by removing the filename_pattern feature, but it might come in handy in future...

# negative_pattern - Same as pattern, but checks for absence of matches.
# named_pattern - A pattern can be reused by specifying it in the
# named_patterns section and referencing it here by its
Expand All @@ -43,6 +44,19 @@ disambiguations:
- pattern: '^[.''][ \t]*TH +(?:[^"\s]+|"[^"]+") +"?(?:[1-9]|@[^\s@]+@)'
- pattern: '^[.''][ \t]*SH +(?:[^"\s]+|"[^"\s]+)'

# Document which uses *no* macros
- language: Text
negative_pattern:
- '^[.''][ \t]*(?:\\")(?=\s|$)'
- '^[.''][ \t]*(?:AT|B|BI|BR|BT|DT|EE|EX|HP|IB|IP|IR|LP|ME|MT|OP|P|PD|PP|PT|R|RB|RE|RI|RS|SB|SH|SM|SS|TH|TP|UC|UE|UR)(?=\s|$)'
- '^[.''][ \t]*(?:%A|%B|%C|%D|%I|%J|%N|%O|%P|%Q|%R|%T|%U|%V|Ac|Ad|An|Ao|Ap|Aq|Ar|At|Bc|Bd|Bf|Bk|Bl|Bo|Bq|Brc|Bro|Brq|Bsx)(?=\s|$)'
- '^[.''][ \t]*(?:Bt|Bx|Cd|Cm|D1|Dc|Dd|Dl|Do|Dq|Dt|Dv|Dx|Ec|Ed|Ef|Ek|El|Em|En|Eo|Er|Es|Ev|Ex|Fa|Fc|Fd|Fl|Fn|Fo|Fr|Ft|Fx)(?=\s|$)'
- '^[.''][ \t]*(?:Hf|Ic|In|It|Lb|Li|Lk|Lp|Ms|Mt|Nd|Nm|No|Ns|Nx|Oc|Oo|Op|Os|Ot|Ox|Pa|Pc|Pf|Po|Pp|Pq|Qc|Ql|Qo|Qq|Re|Rs|Rv)(?=\s|$)'
- '^[.''][ \t]*(?:Sc|Sh|Sm|So|Sq|Ss|St|Sx|Sy|Ta|Tn|Ud|Ux|Va|Vt|Xc|Xo|Xr)(?=\s|$)'
- '^[.''][ \t]*(?:ab|ad|af|am|as|bd|bp|br|c2|cc|ce|cf|ch|cs|cu|da|de|di|ds|dt|ec|el|em|eo|ev|ex|fc|fi|fl|fp|ft|hc|hw)(?=\s|$)'
- '^[.''][ \t]*(?:hy|ie|if|ig|in|it|lc|lg|lf|ll|ls|lt|mc|mk|na|ne|nf|nh|nm|nn|nr|ns|nx|os|pc|pi|pl|pm|pn|po|ps|rd|rm)(?=\s|$)'
- '^[.''][ \t]*(?:rn|rr|rs|rt|so|sp|ss|sv|sy|ta|tc|ti|tl|tm|tr|uf|ul|vs|wh)(?=\s|$)'

# Open-ended fallback to unrendered Roff source
- language: Roff
- extensions: ['.as']
Expand Down
12 changes: 12 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5278,8 +5278,20 @@ Text:
wrap: true
aliases:
- fundamental
- change-log
- changelog
- outline
extensions:
- ".txt"
- ".1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about .0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't associate that extension with Roff, because there's never been a man0 section…

- ".2"
- ".3"
- ".4"
- ".5"
- ".6"
- ".7"
- ".8"
- ".9"
- ".fr"
- ".nb"
- ".ncl"
Expand Down
135 changes: 135 additions & 0 deletions samples/Roff Manpage/atom.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
.de op
. ds o \\fB\\$1\\fP
. ie \\n(.$>2 .as o , \\fB\\$2\\fP \\fI\\$3\\fP
. el .if \\n(.$=2 \{
. length L \\$1
. ie \\nL=2 .as o , \\fB\\$2\\fP
. el .as o " \\fI\\$2\\fP
. rm L
. \}
. TP
\\*o
. rm o
..
.de env
. TP
\\fB\\$1\\fP
..
.
.\" ============================================================================
.TH ATOM 1 v1.26.1
.SH NAME
atom \(em a hackable text editor for the 21st century
.
.SH SYNOPSIS
.B atom
.RI [ options ]
.RI [ "paths..." ]
.
.\" ============================================================================
.SH DESCRIPTION
Opens one or more \fIpaths\fP in Atom, which may point to either files or folders.
.PP
If there is an existing Atom window that contains all of the given folders, the paths will be opened in that window.
Otherwise, they will be opened in a new window.
.PP
Paths that start with \(lqatom://\(rq will be interpreted as URLs.
.
.\" ============================================================================
.SH OPTIONS
.
.op -1 --one ""
This option is no longer supported.
It was formerly used to preview v1.0 APIs, and became redundant once Atom v1.0 shipped.
.
.op -a --add ""
Open path as a new project in last used window.
.
.op --benchmark
Open a new window that runs the specified benchmarks.
.
.op --benchmark-test
Run a faster version of the benchmarks in headless mode.
.
.op --clear-window-state
Delete all Atom environment state.
.
.op -d --dev ""
Run in development mode.
.
.op --enable-electron-logging
Enable low-level logging messages from Electron.
.
.op -f --foreground ""
Keep the main process in the foreground.
.
.op -h --help ""
Print a usage message.
.
.op --include-deprecated-apis
This option is not currently supported.
.
.op -l --log-file file
Log all output to \fIfile\fP.
.
.op -m --main-process ""
Run the specified specs in the main process.
.
.op -n --new-window ""
Open a new window.
.
.op -p --project file
Start Atom with a project specification \fIfile\fP, which may be either CSON or JSON.
.
.op --profile-startup
Create a profile of the startup execution time.
.
.op -r --resource-path path
Set the path to the Atom source directory and enable dev-mode.
.
.op --safe
Do not load packages from
.I ~/.atom/packages
or
.IR ~/.atom/dev/packages .
.
.op -t --test specs
Run the specified
.I specs
and exit with an error code on failure.
.
.op --timeout delay
When in test mode, waits until the specified time (in minutes) and kills the process (exit code: 130).
.
.op -v --version ""
Print the version information.
.
.op -w --wait ""
Wait for window to be closed before returning.
.
.\" ============================================================================
.SH ENVIRONMENT VARIABLES
.env ATOM_DEV_RESOURCE_PATH
The path from which Atom loads source code in dev-mode. Defaults to
.IR ~/github/atom .
.
.env ATOM_HOME
The root path for all configuration files and folders. Defaults to
.IR ~/.atom .
.
.\" ============================================================================
.SH SEE ALSO
.BR apm (1)
.
.PP
The Atom flight manual:
.I http://flight-manual.atom.io/
.
.\" ============================================================================
.SH AUTHORS
Copyright \(co 2011\(en2018, GitHub Inc.
Released under the MIT license.
.
.PP
Manpage written by Alhadis
.RI < gardnerjohng@gmail.com >.
Loading