File: exalias.eg

package info (click to toggle)
elvis 2.1j-2
  • links: PTS
  • area: main
  • in suites: slink
  • size: 4,272 kB
  • ctags: 5,969
  • sloc: ansic: 55,550; sh: 964; makefile: 267
file content (340 lines) | stat: -rw-r--r-- 8,252 bytes parent folder | download
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
alias lf !!ls -CF

alias save {
 "write this file, but only if it has been modified
 if modified
 then w!? !*
}

alias w {
 "write this file, but if readonly then check it out first
 if readonly && "!?!%!*" == ""
 then !!co -l %
 then w!!
 else !%w!? !*
}

alias man split +mantweak !man

alias mantweak {
 "convert nroff output back into man source
 let r=report
 set report=0
 1 s/^Reformatting.*ait\.\.\.$//
 %s/\\/\\\\/g
 %s/_\(.\)/\\fI\1\\fR/g
 %s/.\(.\)/\\fB\1\\fR/g
 %s/\\fR\\fB//g
 %s/\\fR\\fI//g
 1 i .nf
 let report=r
 set bd=man nomod
 dis man
}

alias text {
 "like :tag but for any text
 set tagprgonce="grep -nsw '(quote(\"'\",$1))' *.[ch] /dev/null \| sed 's/^\\\\\\(.*\\\\\\):\\\\\\(.*\\\\\\):.*/!^	\\1	\\2/'"
 tag!? !*
}

alias btext {
 "like :browse but for any text
 set tagprgonce="grep -nsw '(quote(\"'\",$1))' *.[ch] /dev/null \| sed 's/^\\\\\\(.*\\\\\\):\\\\\\(.*\\\\\\):.*/!^	\\1	\\2/'"
 browse!! !*
}

if gui=="x11"
then {
 alias courier {
  "use courier fonts of a given size
  set normalfont=*-courier-medium-r-*-!(18)^-*
  set italicfont=*-courier-medium-o-*-!(18)^-*
  set boldfont=*-courier-bold-r-*-!(18)^-*
 }
}

alias copying split (elvispath("license"))

alias cbload {
 "load cut-buffers from a file
 if "!1" == ""
 then error cbload requires a file name
 let b=buffer
 let r = report
 set report=0
 e !1
 %s:^--CBS-- \([a-z]\)$:+;/^--CBS--/-1 y \1:x
 let report = r
 eval buffer (b)
}

alias cbsave {
 "save cut-buffers to a file
 if "!1" == ""
 then error cbsave requires a file name
 let b = buffer
 let r = report
 set report=0
 e !1
 %d
 let a = 'a'
 while a <= 'z'
 do {
  if buffer("Elvis cut buffer "char(a))
  then {
   eval $ a --CBS-- (char(a))
   eval $ put (char(a))
  }
  let a = a + 1
 }
 $ a --CBS--  
 w!?
 let report = r
 eval buffer (b)
}

alias config {
 "describe the configuration of this elvis
 calc "Display modes:     normal"(feature("syntax")?" syntax")(feature("hex")?" hex")(feature("html")?" html man tex")
 calc "Network protocols: "(feature("ftp")?"ftp":"none")(feature("http")?" http")
 calc "Other features:   "(feature("showtag")?" showtag")(feature("lpr")?" lpr")(feature("alias")?" alias")(feature("mkexrc")?" mkexrc")(feature("complete")?" complete")(feature("ram")?" ram")
}

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" The following were contributed by Ian Utley (iu@apertus.uk.com)

alias align {
    "align any = signs (or other given text) in selected line
    "
    " The following if tests to see if we have visually highlighted lines.
    "
    let f=0
    if ( !> !!= "" )
    then {
        !< mark a
        !> mark b
        let f=1
    }
    if ( f == 1)
    then {
        "
        " Initialise i which will store the alignment column. Switch off
        " reporting and mark the current line to return the cursor at the end.
        "
        set i=0
        let j=report
        set report=0
        mark z
        "
        " Remove any whitespace before the alignment character.
        "
        'a,'b s/[ 	]*!(=)\$/!(=)\$/
        "
        " We could be aligning != <= or >= so we want to keep this letter
        " near. Of course we may not be aligning an equals but we commonly do.
        "
        if ( "!(=)\$" == "=" )
        then {
            'a,'b s/[	 ]*\([!!<>]*\)!(=)\$[	 ]*/ \1!(=)\$ /
        } 
        "
        "
        let f=0
        'a,'bglobal /!(=)\$/ {
            " 
            " Special case for the top line as -1 will not work.
            "
            if ( current("line") == 1 )
            then {
                1 insert ""
                let f=1
            }
            -1
            /!(=)\$
            "
            "
            " Remember the largest column number for alignment.
            "
            if (current("column")>i)
            then let i=current("column")
            "
            " Special case removal
            "
            if ( current("line") > 1 && f == 1)
            then {
                1 delete
                let f=0
            }
        }
        "
        " Do the alignment.
        "
        let f=0
        'a,'bglobal /!(=)\$/ {
            " 
            " Special case for the top line as -1 will not work.
            "
            if ( current("line") == 1 )
            then {
                1i ""
                let f=1
            }
            -1
            /!(=)\$
            "
            " Not sure why I need to add +1
            "
            let k=i-current("column")+1
            s/\([!!<>]*\)!(=)\$/                                                                                \1!(=)\$/
            eval s/ *\\\( \{(k)\}[!!<>]*!(=)\$\\\)/\1
            "
            " Special case removal
            "
            if ( current("line") > 1 && f == 1 )
            then {
                1 delete
                let f=0
            }
        }
        "
        " Restore the reporting to its previous level, and return the cursor
        " to the line it was previously on.
        "
        let report=j
        'z
    }
}


alias match {
    " match "if" with "endif", etc.
    "
    if ( ! ignorecase )
    then {
        "
        " Openroad is case-insensitive and so we set the ignorecase option for 
        " searches, but remembering the current setting.
        "
        set k=1
        set ignorecase
    }
    "
    " Initialize variables
    "
    set z=0
    set a=""
    set b=""
    set d=""
    " 
    " Remember where we started.
    "
    mark d
    let a=current("word")
    if (a != "")
    then {
        let a=toupper(a)
        if ( a=="IF" || a=="FOR" || a=="WHILE")
        then {
            let b="END" a
            let d="forward"
        }
        if ( a=="ENDIF" || a=="ENDFOR" || a=="ENDWHILE" )
        then {
             if ( a=="ENDIF" ) 
             then let b="IF"
             if ( a=="ENDFOR" )
             then let b="FOR"
             if ( a=="ENDWHILE" )
             then let b="WHILE"
             let d="backward"
        }
        if ( b=="" )
        then error Not a matching keyword
        if ( d=="forward" )
        then {
            "
            " We are searching forward, so put a sentinal at the end of
            " the file to ensure that the search succeeds.
            "
            eval $ append (b)
            'd
        }
        else {
            "
            " We are searching backwards, so put a sentinal at the start of
            " the file to ensure that the search succeeds.
            "
            eval 1 insert (b)
            'd
        }
        mark c
        set i=1
        "
        " z = 1 when we reach the start, or end of the file.
        "
        while (i != 0 && z==0 )
        do {
            if ( d=="forward" )
            then {
                eval /\<(b)\>
                if (current("line")==buflines)
                then {
                    set z=1
                    $ delete
                }
            }
            else {
                'd
                eval ?\<(b)\>
                if (current("line")==1)
                then {
                    set z=1
                    1 delete
                }
            }
            mark d
            set i=0
            if ( d=="forward" )
            then {
                eval 'c,'d global /\<(a)\>/ let i=i+1
                eval 'c,'d global /\<(b)\>/ let i=i-1
            }
            else {
                eval 'd,'c global /\<(a)\>/ let i=i+1
                eval 'd,'c global /\<(b)\>/ let i=i-1
            }
        }
        if (z==1)
        then {
            'c
            error Match not found!
        }
        else {
            "
            " Clean up the sentinels
            "
            if ( d=="forward" )
            then {
                $ delete
                " Lets attempt to put the cursor on the word.
                'd-1
                eval /\<(b)\>
            }
            else {
                1 delete
                " Lets attempt to put the cursor on the word.
                'd+1
                eval ?\<(b)\>
            }
        }
    }
    "
    " Restore the ignorecase option if necessary 
    "
    if (k==1)
    then {
        set noignorecase
        set k=0
    }
}