-
Notifications
You must be signed in to change notification settings - Fork 0
/
dtrt-indent.elc
137 lines (118 loc) · 24.3 KB
/
dtrt-indent.elc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
;ELC
;;; Compiled by shant@ultraio on Sat Sep 27 19:36:32 2014
;;; from file /home/shant/.emacs.d/dtrt-indent.el
;;; in Emacs version 24.3.1
;;; with all optimizations.
;;; This file uses dynamic docstrings, first added in Emacs 19.29.
;;; This file does not contain utf-8 non-ASCII characters,
;;; and so can be loaded in Emacs versions earlier than 23.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#@114 Non-nil if Dtrt-Indent mode is enabled.
See the command `dtrt-indent-mode' for a description of this minor mode.
(custom-declare-variable 'dtrt-indent-mode nil '(#$ . 506) :set 'custom-set-minor-mode :initialize 'custom-initialize-default :group 'dtrt-indent :type 'boolean)
#@294 Toggle dtrt-indent mode.
With no argument, this command toggles the mode. Non-null prefix
argument turns on the mode. Null prefix argument turns off the
mode.
When dtrt-indent mode is enabled, the proper indentation
offset will be guessed for newly opened files and adjusted
transparently.
(defalias 'dtrt-indent-mode #[(&optional arg) "\303 \304=\203 \n?\202 \305 !\306V\307\310\n\203 \311\202 \312\"\210\313\314!\203D \315\302!\210\303 \2037 \303 \232\203D \316\317\n\203A \320\202B \321\"\210)\322 \210\n\207" [#1=#:last-message arg dtrt-indent-mode current-message toggle prefix-numeric-value 0 run-hooks dtrt-indent-mode-hook dtrt-indent-mode-on-hook dtrt-indent-mode-off-hook called-interactively-p any customize-mark-as-set message "Dtrt-Indent mode %sabled" "en" "dis" force-mode-line-update] 3 (#$ . 788) (list (or current-prefix-arg 'toggle))])
(byte-code "\301\302\303\304\300!\205\n \303\211%\207" [dtrt-indent-mode-map add-minor-mode dtrt-indent-mode nil boundp] 6)
#@1123 A list of syntax tables for supported languages.
Each entry in this list is of the form
(SYMBOL SYNTAX-ENTRY [SYNTAX-ENTRY [...]])
where SYMBOL is used to identify the language in
question and SYNTAX-ENTRY is in format
(BEGIN-REGEXP NUM-GROUPS END-REGEXP RECURSIVE-P SKIP-REGEXP)
BEGIN-REGEXP is a regular expression matching the beginning of
the syntax construct in question. NUM-GROUPS indicates how many
groups there are in BEGIN-REGEXP to be substituted in END-REGEXP.
END-REGEXP is a regular expression matching the end of the syntax
construct in question. It can refer back to one group in
BEGIN-REGEXP using . Currently only one group is supported (
cannot be used.)
RECURSIVE-P indicates whether other syntax constructs can be
nested within this construct. RECURSIVE-P is usually false for
comment and constant constructs, such as strings, and usually
true for bracketing constructs.
SKIP-REGEXP is a regular expression that, if matches, means that
END-REGEXP is ignored for that location. This can be used to
prevent an escaped quote from being interpreted as the closing
quote, for example.
(defvar dtrt-indent-language-syntax-table '((c/c++/java ("\"" 0 "\"" nil "\\\\.") ("'" 0 "'" nil "\\\\.") ("[/][*]" 0 "[*][/]" nil) ("[/][/]" 0 "$" nil) ("(" 0 ")" t) ("\\[" 0 "\\]" t)) (perl ("\"" 0 "\"" nil "\\\\.") ("'" 0 "'" nil "\\\\.") ("[#]" 0 "$" nil) ("(" 0 ")" t) ("\\[" 0 "\\]" t)) (ruby ("\"" 0 "\"" nil "\\.") ("'" 0 "'" nil "\\.") ("#" 0 "$" nil) ("(" 0 ")" t) ("\\[" 0 "\\]" t) ("{" 0 "}" t)) (ada ("\"" 0 "\"" nil "\\.") ("--" 0 "$" nil) ("(" 0 ")" t) ("\\[" 0 "\\]" t) ("{" 0 "}" t)) (erlang ("\"" 0 "\"" nil "\\.") ("[<][<]\"" 0 "\"[>][>]" nil) ("%" 0 "$" nil) ("{" 0 "}" t) ("\\[" 0 "\\]" t) ("(" 0 ")" t) ("\\b\\(begin\\|case\\|fun\\|if\\|receive\\|try\\)\\b" 0 "\\bend\\b" t)) (css ("\"" 0 "\"" nil "\\\\.") ("'" 0 "'" nil "\\\\.") ("[/][*]" 0 "[*][/]" nil)) (shell ("\"" 0 "\"" nil "\\.") ("'" 0 "'" nil "\\.") ("[<][<]\\\\?\\([^ ]+\\)" 1 "^\\1" nil) ("(" 0 ")" t) ("\\[" 0 "\\]" t))) (#$ . 1787))
#@50 A mapping from hook variables to language types.
(defvar dtrt-indent-hook-mapping-list '((c-mode c/c++/java c-basic-offset) (c++-mode c/c++/java c-basic-offset) (java-mode c/c++/java c-basic-offset) (jde-mode c/c++/java c-basic-offset) (js-mode c/c++/java js-indent-level) (objc-mode c/c++/java c-basic-offset) (php-mode c/c++/java c-basic-offset) (perl-mode perl perl-indent-level) (erlang-mode erlang erlang-indent-level) (ruby-mode ruby ruby-indent-level) (ada-mode ada ada-indent) (sh-mode shell sh-basic-offset) (css-mode css css-indent-offset) (pascal-mode pascal pascal-indent-level)) (#$ . 3836))
(byte-code "\300\301\302\303\304\305\306\307\306\310& \210\311\312\302\313\314\315\316\317\304\305\320\321\306\301\322\301&\210\311\323\324\325\320\326\327\330\306\301& \210\311\331\302\332\320\321\327\333\306\301& \210\311\334\335\336\320\337\327\340\306\301& \210\311\341\342\343\320\337\327\344\306\301& \210\311\345\346\347\320\350\327\351\306\301& \210\311\352\353\354\320\350\327\355\306\301& \210\311\356\357\360\320\350\327\361\306\301& \210\311\362\363\364\320\350\327\365\306\301& \210\311\366\367\370\320\350\327\371\306\301& \210\311\372\302\373\320\321\327\374\306\301& \210\311\375\324\376\320\337\327\377\306\301& \210\311\201@ \335\201A \320\337\327\201B \306\301& \210\311\201C \201D \201E \320\337\327\201F \306\301& \210\311\201G \201H \201I \320\201J \327\201K \306\301& \210\201L \201M !\210\201L \201N !\210\201L \201O !\210\201L \201P !\207" [custom-declare-group dtrt-indent nil "Transparently adapt to foreign indentation offsets." :version "22.0" :group files convenience custom-declare-variable dtrt-indent-mode "Toggle adaptive indentation mode.\nSetting this variable directly does not take effect;\nuse either \\[customize] or the function `dtrt-indent-mode'." :set #[(symbol value) " \206 \302!\207" [symbol value 0] 2] :initialize custom-initialize-default :type boolean :require dtrt-indent-verbosity 1 "*Verbosity level.\n\nHow much dtrt-indent should tell you about what it's doing. If\nthis is 1, the default, dtrt-indent will only let you know when\nit adjusts the indentation offset but will be silent otherwise.\nBy setting this to 2 it will also tell you why it didn't adjust\nthe offset. You might want to try this as a first measure if\nyou're unhappy with dtrt-indent's actions. A setting of 3 will\noutput lots of diagnostic information. Finally, a setting of 0\nkeeps dtrt-indent of ever outputting anything." (choice (const :tag "Silent" 0) (const :tag "Normal" 1) (const :tag "Verbose" 2) (const :tag "Diagnostics" 3)) :tag "Verbosity" dtrt-indent-require-confirmation-flag "*Non-nil means to ask for confirmation before making adjustments.\n\nWhether dtrt-indent asks for confirmation whenever it is about to\nmake any adjustments. By default, adjustments are made without\nyour explicit consent because dtrt-indent is already quite\nconservative and tries to 'do the right thing', adjustments can\nbe undone easily, and they aren't harmful in the first place.\nHowever, if you feel like it's doing things behind your back\nyou should enable this setting." "Require Confirmation" dtrt-indent-min-relevant-lines 2 "*Minimum number of relevant lines required for a guess to be made.\n\nThis check is in place because with a very low number of lines\nthat can be analyzed the chances of a wrong guess are rather\nhigh because the sample size is so small. If you are getting\nfalse positives with small files - i.e. the wrong offset is guessed\n- you might want to increase this setting. On the other hand, if\nyou are getting false negatives on small files - i.e. no guess is\nmade on a small file - you might want to decrease it." integer "Minimum Number Of Relevant Lines" dtrt-indent-max-relevant-lines 500 "*Maximum number of relevant lines to be considered in analysis.\n\nThis setting is meant to prevent dtrt-indent from spending large\namounts of time on analyzing large source files. In general, the\nhigher this setting, the more accurate the guess will be but the\nmore time dtrt-indent will consume when opening files. If you\nhave a fast box you might want to consider increasing this\nnumber. On the other hand, if you find that dtrt-indent\nintroduces a noticable delay when opening files you might want\nto decrease it." "Maximum Number Of Relevant Lines" dtrt-indent-min-quality 80.0 "*Minimum quality for an indentation offset to be accepted.\n\nPercentage (0-100) of lines that are indented by a non-zero\namount of spaces divisible by a given offset required for that\noffset to be eligible for guessing. A value of 80 means that for\ninstance, an indentation level of 4 will only be guessed if at\nleast 80% of all lines are indented by an offset divisible by 4.\n\nThis setting essentially controls how lenient or conservative\ndtrt-indent operates. If you are getting false positives -\ni.e. guess-offset guesses the wrong offset - you might want to\nincrease this setting. On the other hand, if you are getting\nfalse negatives - i.e. guess-offset refuses to adjust the offset\n- you might want to decrease it." float "Minimum Number Of Matching Lines" dtrt-indent-min-indent-superiority 100.0 "*Minimum percentage the best guess needs to be better than second best.\n\nThe percentage (0-100, but higher values than 100 are possible)\nthat the number of lines matching the best guess must be higher\nthan the number of lines matching the second best guess in order\nfor dtrt-indent to adjust the offset. For example, a value of\n100 means that there must be twice as many lines matching the\nbest guess than the number of lines matching the second best\nguess.\n\nThis check is in place to avoid a good guess to be accepted if\nthere is another, similarly good guess, because in that situation\nthere is ambiguity and no single reliable guess. If you are\ngetting false positives - i.e. dtrt-indent guesses the wrong\noffset - you might want to increase this setting. On the other\nhand, if you are getting false negatives - i.e. dtrt-indent\nrefuses to adjust the offset - you might want to decrease it." "Minimum Superiority Of Best Guess" dtrt-indent-min-soft-tab-superiority 300.0 "*Minimum percentage soft-tab lines need to outnumber hard-tab ones.\n\nTBD" "Minimum Superiority Of Soft Tabs" dtrt-indent-min-hard-tab-superiority 300.0 "*Minimum percentage hard-tab lines need to outnumber soft-tab ones.\n\nTBD" "Minimum Superiority Of Hard Tabs" dtrt-indent-max-merge-deviation 20.0 "*Minimum difference between offsets divisible without remainder.\n\nThe percentage of difference in the number of lines that are\nmatched by two guessed offsets where the larger offset is\ndivisible by the smaller without remainder for the smaller offset\nto be discarded.\n\nThis setting is in place because without it, in a file with 1000\nlines matching an offset of 4, all of those 1000 lines are also\nmatching an offset of 2 and a number of stray lines whose offset\nis divisible by 2 but not by 4 would confuse dtrt-indent to treat\nthe smaller offset as the better guess. By discarding the\nsmaller offset with some tolerance, this problem is avoided.\n\nIf you notice that often, sub-offsets are wrongly guessed (e.g. 8\nwould be the proper offset but 4 is guessed, or 6 would be\ncorrect but 3 is guessed) you might want to decrease this\nsetting. On the other hand, if super-offsets are guessed (e.g. 4\nwould be appropriate, but 8 is guessed) you might want to\nincrease it." "Maximum Deviation For Sub-Offset Merging" dtrt-indent-ignore-single-chars-flag "*Non-nil means ignore lines containing only a single character.\n\nWhether to treat lines that contain only a single non-whitespace\ncharacter as irrelevant for the analysis. Set this to t in to\nprevent hanging braces etc. from skewing the results. Set it to\nnil if you are dealing with source files whose indentation level\nisn't reliably guessed without those lines." "Ignore Single-Character Lines" dtrt-indent-min-matching-indentations "*Minimum number of distinct levels for an offset to be eligible.\n\nThe minimum number of distinct, non-zero indentation levels\nmatching a given offset required to be present in a file for that\noffset to be eligible for guessing. A value of 2 means that for\ninstance, an indentation level of 4 will only be guessed if some\nlines are indented at 4 spaces and some at 8; or if some lines\nare indented at 12 spaces and some at 20; but not if some lines\nare indented at 4 spaces but there are no other lines indented at\nan offset divisible by 4.\n\nThe default value of 1 effectively disables any such requirement.\nIf you are getting false positives, you might want to set this to\na higher value such as 2. However, a value of 2 means that the\noffset won't be guessed for files containing only 'flat'\nconstructs" "Minimum Depth" dtrt-indent-min-offset "*Minimum indentation offset that can be guessed.\n\nYou usually don't want to tinker with this - setting it to a\nhigher value than 2 means that the rather common offset of 2 will\nno longer be guessed. Setting it to 1 will likely screw up\ndtrt-indent algorithms because every line in every source code\nmatches that indentation level." "Minimum Guessed Indentation Offset" dtrt-indent-max-offset 8 "*Maximum indentation offset that can be guessed.\n\nYou usually don't want to tinker with this - setting it to a\nlower value than 8 means that the (unfortunately) rather common\nindentation offset of 8 will no longer be guessed. Setting it to\na higher value than 8 should not be harmful, but source files\nusing more than 8 spaces per indentation level are very rare." "Maximum Guessed Indentation Offset" dtrt-indent-accept-file-function (lambda (filename) t) "*Acceptor determining which files are analyzed.\n\nThis function will be called for every file dtrt-indent would\nnormally analyze with one argument, the file name. Only if it\nreturns a non-nil value analysis will be performed on the file.\n\nBy default, all files are analyzed." function "Analysed File Inclusion Function" make-variable-buffer-local dtrt-indent-original-indent dtrt-indent-mode-line-info dtrt-indent-explicit-offset dtrt-indent-explicit-tab-mode] 16)
#@132 Replace every match in string by constant replacement.
Returns HAYSTACK with every match of NEEDLE-REGEXP replaced by
REPLACEMENT.
(defalias 'dtrt-indent--replace-in-string #[(haystack needle-regexp replacement) "\303 \"\203 \304\211\224O\n \304\225\305OQ\207 \207" [needle-regexp haystack replacement string-match 0 nil] 5 (#$ . 14042)])
#@318 Place point at the end of the current match.
END-REGEX is a regular expression matching the end. If
SKIP-REGEX matches though, END-REGEX is ignored.
SYNTAX-REGEX-PAIRS is a list of syntax entries as described for
`dtrt-indent-language-syntax-table'. MULTI-LINE, if false,
constrains the search to the current line.
(defalias 'dtrt-indent--skip-to-end-of-match #[(end-regex skip-regex syntax-regex-pairs multi-line) "\306\307\211\310\311\312\205 TC\f\205 T\fC\313\314\"#\315#\316?\2057 \212\307\210`)\317#\205\327 \306\320 G\321\245\211X\203\\ \224\204\\ T\211\202G =\203g \307\202\320 \n=\203r \317\202\320 Z@A@V\203\232 \322@A@\306#A\202{ @* \323 A@\324V\203\273 \325\321 8\326\327\330T!!#\202\277 \321 8\331 8\332 8\205\313 \317$\210)\317*\205\327 \202( ,\207" [index-offset end-index skip-index end-regex skip-regex syntax-regex-pairs 1 nil mapconcat #[(el) "\301\302Q\207" [el "\\(" "\\)"] 3] append mapcar #[(x) "@\207" [x] 1] "\\|" re-search-forward t match-data 2 - dtrt-indent--skip-to-end-of-match 0 dtrt-indent--replace-in-string "[\\][1]" regexp-quote match-string-no-properties 4 3 regexp multi-line match-count match-index syntax-regex-iterator matching-syntax-entry] 9 (#$ . 14391)])
#@266 Call a function for each indentation found.
LANGUAGE is used to lookup a syntax table for excluding lines
from the process. For each line not excluded, FUNC is called
with USER-DATA as its argument and with point on the first
non-whitespace character of the line.
(defalias 'dtrt-indent--for-each-indentation #[(language func user-data) "\212eb\210\305\306\307\310#\2050 !\2050 \311\307\211\312\n\"A\307$\210\313 \210`\307y\210\f`)=?\2050 \202 )\207" [func user-data language dtrt-indent-language-syntax-table here re-search-forward "^[ ]*" nil t dtrt-indent--skip-to-end-of-match assoc beginning-of-line] 6 (#$ . 15673)])
#@160 Calculate an indendation histogram.
The histogram is calculated for the current buffer using LANGUAGE
to determine which lines to exclude from the histogram.
(defalias 'dtrt-indent--calc-histogram #[(language) "\306 \307\211\310\311\n\307B#\210\312\307\313\314\n\"\210\f F-\207" [soft-tab-line-count hard-tab-line-count histogram language total-lines histogram-list make-hash-table 0 dtrt-indent--for-each-indentation #[(histogram-and-count) "i\305V\203@ \306\307!\204@ \203 \212\310u\210\306\311!)\204@ \312i\313i @\305#T @#\210\314 \210\306\315!\2037 \nT\202: T \211AT\241\210 A\fW\207" [dtrt-indent-ignore-single-chars-flag histogram-and-count hard-tab-line-count soft-tab-line-count dtrt-indent-max-relevant-lines 0 looking-at "$" nil "[ ]*$" puthash gethash beginning-of-line "[ ]+"] 6] nil maphash #[(key value) "\304 \nDC\"\n\\\211\207" [histogram-list key value total-lines append] 4]] 5 (#$ . 16310)])
#@691 Return match information for the given offset.
TRY-OFFSET is the offset to try, HISTOGRAM is the previously
calculated indentation histogram, TOTAL-LINES is the total number
of lines for which the histogram was calculated.
Returns a list in the format (TRY-OFFSET, PERCENTAGE,
MATCHING-INDENTATIONS, REJECT-REASON) where TRY-OFFSET is the
offset that was passed in as the first argument, PERCENTAGE is
the percentage of lines (0..1) with indentation levels that are a
multiple of TRY-OFFSET, MATCHING-INDENTATIONS is the number of
distinct indentation levels found that are a multiple of
TRY-OFFSET, and REJECT-REASON, if non-nil, is a string explaining
why TRY-OFFSET should be rejected.
(defalias 'dtrt-indent--analyze-histogram-try-offset #[(try-offset histogram total-lines) "\306\211\n\307\211\203) \f@\310@\"\306=\203\"