1
0
mirror of https://github.com/amix/vimrc synced 2025-09-15 00:24:59 +08:00

Add support of auto format files.

This commit is contained in:
Kurtis Moxley
2022-05-20 17:05:00 +08:00
parent 25e4662559
commit cdd9fbbddb
25 changed files with 12539 additions and 27 deletions

View File

@ -0,0 +1,4 @@
using System; class Program { static int Main(string[] args) { Console.WriteLine(args[0]); int i = 0; i++; return 0; }
public int Foo() { switch (1) { case 1: int i = 0; default: int j = 1; }
}
}

View File

@ -0,0 +1,258 @@
module prettify_selftest
implicit none
private
public :: dp, test_routine, &
test_function, test_type, str_function
integer, parameter :: dp = selected_real_kind ( 15 , 307)
type test_type
real (kind =dp ) :: r = 1.0d-3
integer :: i
end type test_type
contains
subroutine test_routine( &
r, i, j, k, l)
integer, intent(in) :: r, i, j, k
integer, intent (out) :: l
l = test_function(r,i,j,k)
end &
subroutine
pure function test_function(r, i, j, &
k) &
result(l)
integer, intent(in) :: r, i, j, k
integer :: l
l=r + i +j +k
end function
function &
str_function(a) result(l)
character(len=*) :: a
integer :: l
if(len(a)<5)then
l=0
else
l=1
endif
end function
end module
program example_prog
use example, only: dp, test_routine, test_function, test_type,str_function
implicit none
integer :: r,i,j,k,l,my_integer,m
integer, dimension(5) :: arr
integer, dimension(20) :: big_arr
integer :: endif
type(test_type) :: t
real(kind=dp) :: r1, r2, r3, r4, r5, r6
integer, pointer :: point
point=> null( )
! 1) white space formatting !
!***************************!
! example 1.1
r=1;i=-2;j=3;k=4;l=5
r2 = 0.0_dp; r3= 1.0_dp; r4 =2.0_dp; r5=3.0_dp; r6 = 4.0_dp
r1=-(r2**i*(r3+r5*(-r4)-r6))-2.e+2
if( r.eq.2.and.r<=5) i=3
write(*, *)(merge(3, 1, i<=2))
write(*, *)test_function(r,i,j , k)
t % r = 4.0_dp
t%i = str_function( "t % i = " )
! example 1.2
my_integer=2
i=3
j=5
big_arr = [1, 2, 3, 4, 5, &
6, 7, 8, 9, 10, &
11, 12, 13, 14, 15, &
16, 17, 18, 19, 20]
! example 1.3: disabling auto-formatter:
my_integer = 2 !&
i = 3 !&
j = 5 !&
!&<
my_integer = 2
i = 3
j = 5
!&>
big_arr = [ 1, 2, 3, 4, 5, & !&
6, 7, 8, 9, 10, & !&
11, 12, 13, 14, 15, & !&
16, 17, 18, 19, 20] !&
! example 1.4:
big_arr = [1, 2, 3, 4, 5,&
& 6, 7, 8, 9, 10, &
& 11, 12, 13, 14, 15,&
&16, 17, 18, 19, 20]
! 2) auto indentation for loops !
!*******************************!
! example 2.1
l = 0
do r= 1 , 10
select case (r)
case(1)
do_label: do i = 1,100
if (i<=2) then
m =0
do while(m <4)
m =m+1
do k=1,3
if (k==1) l =l +1
end do
enddo
endif
enddo do_label
case ( 2 )
l=i + j + k
end select
enddo
! example 2.2
do m = 1, 2
do r = 1, 3
write (*, *) r
do k = 1, 4
do l = 1, 3
do i = 4, 5
do my_integer = 1, 1
do j = 1, 2
write (*, *) test_function(m, r, k, l) + i
enddo
enddo
enddo
enddo
enddo
enddo
enddo
! 3) auto alignment for linebreaks !
!************************************!
! example 3.1
l = test_function(1, 2, test_function(1, 2, 3, 4), 4) + 3 *(2+1)
l = test_function (1, 2, test_function(1,2, 3, 4),4) +&
3*(2+ 1 )
l = test_function(1, 2, &
test_function(1, 2, 3, 4), 4)+ &
3 * (2+1)
l = test_function(1, 2, &
test_function(1, 2, 3, &
4), 4) + &
3*(2 + 1)
! example 3.2
arr = [1, (/3,4, 5/), 6] + [ 1, 2,3, 4,5 ]
arr = [1,(/ 3, 4, 5 /) , &
6] +[1,2, 3, 4, 5 ]
arr = [1,(/3,4,5/), &
6]+ &
[1, 2, 3, 4, 5]
arr = [1, (/3, 4, &
5/), &
6] + &
[1, 2,3, 4, 5 ]
! example 3.3
l = test_function(1, 2, &
3, 4)
l = test_function( &
1, 2, 3, 4)
arr = [1, 2, &
3, 4, 5]
arr = [ &
1, 2, 3, 4, 5]
! 4) more complex formatting and tricky test cases !
!**************************************************!
! example 4.1
l = 0
do r = 1, 10
select case ( r )
case( 1)
do i=1,100;if (i<=2) then! comment
do j = 1,5
do k= 1, 3
l = l + 1
! unindented comment
! indented comment
end do; enddo
elseif ( .not. j ==4 ) then
my_integer = 4
else
write (*,*) " hello"
endif
enddo
case(2 )
l = i+ j + k
end select
enddo
! example 4.2
if ( &
l == &
111) &
then
do k = 1, 2
if (k == 1) &
l = test_function(1, &
test_function(r=4, i=5, &
j=6, k=test_function(1,2*(3*(1 +1)), str_function ( ")a!(b['(;=dfe"), &
9) + &
test_function(1, 2, 3, 4)), 9, 10) &
! test_function(1,2,3,4)),9,10) &
! +13*str_function('') + str_function('"')
+ 13*str_function('') + str_function('"')
end & ! comment
! comment
do
endif
! example 4.3
arr = [1,( /3,4, &
5 /),&
6 ]+ &
[1,2, 3, 4,5] ; arr = [1, 2,&
3, 4, 5]
! example 4.4
endif = 3
if(endif==2)then
endif=5
else if(endif==3)then
write(*,*)endif
endif
! example 4.5
do i=1,2;if(.true.)then
write(*, *)"hello"
endif; enddo
end program

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
public class Blastoff{ public static void main(String[] args) { public static void countdown(int n, int m) { if (n == 0) { System.out.println("Blastoff!"); } else { System.out.println(n); countdown(n - 1); } } }}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,92 @@
# Examples from perltidy webpage.....
#Some code with side comments
my $lines = 0; # checksum: #lines
my $bytes = 0; # checksum: #bytes
my $sum = 0; # checksum: system V sum
my $patchdata = 0; # saw patch data
my $pos = 0; # start of patch data
my $endkit = 0; # saw end of kit
my $fail = 0; # failed
#A loop
$_ = <<'EOL';
$url = new URI::URL "http://www/"; die if $url eq "xXx";
EOL
LOOP:{print(" digits"),redo LOOP if/\G\d+\b[,.;]?\s*/gc;print(" lowercase"),
redo LOOP if/\G[a-z]+\b[,.;]?\s*/gc;print(" UPPERCASE"),redo LOOP
if/\G[A-Z]+\b[,.;]?\s*/gc;print(" Capitalized"),
redo LOOP if/\G[A-Z][a-z]+\b[,.;]?\s*/gc;
print(" MiXeD"),redo LOOP if/\G[A-Za-z]+\b[,.;]?\s*/gc;print(
" alphanumeric"),redo LOOP if/\G[A-Za-z0-9]+\b[,.;]?\s*/gc;print(" line-noise"
),redo LOOP if/\G[^A-Za-z0-9]+/gc;print". That's all!\n";}
#A hash definition list
%unitscale=("in",72,"pt",72.27/72,"pc",12,"mm",72/25.4,"cm",72/2.54,
"\\hsize",100,"\\vsize",100,"\\textwidth",100,"\\textheight",100,
"\\pagewidth",100,"\\linewidth",100);
#A matrix
my $a_box = [ [ $a11, $a12, $a13, $a14, $a15, $a16 ],
[ $a21, $a22, $a23, $a24, $a25, $a26 ], [ $a31, $a32, $a33, $a34, $a35, $a36 ],
[ $a41, $a42, $a43, $a44, $a45, $a46 ], [ $a51, $a52, $a53, $a54, $a55, $a56 ],
[ $a61, $a62, $a63, $a64, $a65, $a66 ], ];
#A complex data structure
%TV=(flintstones=>{series=>"flintstones",nights=>[qw(monday thursday friday)],
members=>[{name=>"fred",role=>"lead",age=>36,},{name=>"wilma",role=>"wife",
age=>31,},{name=>"pebbles",role=>"kid",age=>4,},],},jetsons=>{series=>"jetsons",
nights=>[qw(wednesday saturday)],members=>[{name=>"george",role=>"lead",age=>41,
},{name=>"jane",role=>"wife",age=>39,},{name=>"elroy",role=>"kid",age=>9,},],},
simpsons=>{series=>"simpsons",nights=>[qw(monday)],members=>[{name=>"homer",
role=>"lead",age=>34,},{name=>"marge",role=>"wife",age=>37,},{name=>"bart",
role=>"kid",age=>11,},],},);
#Cleaning up code from a code generator
#A good application of perltidy is to clean up code which has been produced by a code generator. Here is a snippet advent.t which was generated from Fortran source by a translation tool.
{
L9140:
if ($msccom::obj==$msccom::food) {
goto L8142;
}
if ($msccom::obj==$msccom::bird||$msccom::obj==$msccom::snake||$msccom::obj==$msccom::clam||$msccom::obj==$msccom::oyster||$msccom::obj==$msccom::dwarf||$msccom::obj==$msccom::dragon||$msccom::obj==$msccom::troll||$msccom::obj==$msccom::bear) {
$msccom::spk=71;
}
goto L2011;
#
# DRINK. IF NO OBJECT, ASSUME WATER AND LOOK FOR IT HERE. IF WATER IS
# THE BOTTLE, DRINK THAT, ELSE MUST BE AT A WATER LOC, SO DRINK STREAM.
#
L9150:
if ($msccom::obj==0&&$liqloc->($placom::loc)!=$msccom::water&&($liq->(0)!=$msccom::water||!$here->($msccom::bottle))) {
goto L8000;
}
if ($msccom::obj!=0&&$msccom::obj!=$msccom::water) {
$msccom::spk=110;
}
if ($msccom::spk==110||$liq->(0)!=$msccom::water||!$here->($msccom::bottle)) {
goto L2011;
}
$placom::prop->($msccom::bottle)=1;
$placom::place->($msccom::water)=0;
$msccom::spk=74;
goto L2011;
#
# RUB. YIELDS VARIOUS SNIDE REMARKS.
#
L9160:
if ($msccom::obj!=$placom::lamp) {
$msccom::spk=76;
}
goto L2011;
#
# THROW. SAME AS DISCARD UNLESS AXE. THEN SAME AS ATTACK EXCEPT IGNOR
# AND IF DWARF IS PRESENT THEN ONE MIGHT BE KILLED. (ONLY WAY TO DO SO
# AXE ALSO SPECIAL FOR DRAGON, BEAR, AND TROLL. TREASURES SPECIAL FOR
#
L9170:
if ($toting->($msccom::rod2)&&$msccom::obj==$msccom::rod&&!$toting->($msccom::rod)) {
$msccom::obj=$msccom::rod2;
}
}

View File

@ -0,0 +1,208 @@
#! /usr/bin/env python
"""Tkinter-based GUI for websucker.
Easy use: type or paste source URL and destination directory in
their respective text boxes,click GO or hit return,and presto.
"""
from Tkinter import *
import Tkinter
import websucker
import sys
import os
import threading
import Queue
import time
VERBOSE=2
try:
class Canceled(Exception):
"Exception used to cancel run()."
except (NameError,TypeError):
Canceled=__name__+".Canceled"
class SuckerThread(websucker.Sucker):
stopit=0
savedir=None
rootdir=None
def __init__(self,msgq):
self.msgq=msgq
websucker.Sucker.__init__(self)
self.setflags(verbose=VERBOSE)
self.urlopener.addheaders=[('User-agent','websucker/%s'%websucker.__version__),]
def message(self,format,*args):
if args:
format=format%args
##print format
self.msgq.put(format)
def run1(self,url):
try:
try:
self.reset()
self.addroot(url)
self.run()
except Canceled:
self.message("[canceled]")
else:
self.message("[done]")
finally:
self.msgq.put(None)
def savefile(self,text,path):
if self.stopit:
raise Canceled
websucker.Sucker.savefile(self,text,path)
def getpage(self,url):
if self.stopit:
raise Canceled
return websucker.Sucker.getpage(self,url)
def savefilename(self,url):
path=websucker.Sucker.savefilename(self,url)
if self.savedir:
n=len(self.rootdir)
if path[:n] == self.rootdir:
path=path[n:]
while path[:1] == os.sep:
path=path[1:]
path=os.path.join(self.savedir,path)
return path
def XXXaddrobot(self,*args):
pass
def XXXisallowed(self,*args):
return 1
class App:
sucker=None
msgq=None
def __init__(self,top):
self.top=top
top.columnconfigure(99,weight=1)
self.url_label=Label(top,text="URL:")
self.url_label.grid(row=0,column=0,sticky='e')
self.url_entry=Entry(top,width=60,exportselection=0)
self.url_entry.grid(row=0,column=1,sticky='we',
columnspan=99)
self.url_entry.focus_set()
self.url_entry.bind("<Key-Return>",self.go)
self.dir_label=Label(top,text="Directory:")
self.dir_label.grid(row=1,column=0,sticky='e')
self.dir_entry=Entry(top)
self.dir_entry.grid(row=1,column=1,sticky='we',
columnspan=99)
self.go_button=Button(top,text="Go",command=self.go)
self.go_button.grid(row=2,column=1,sticky='w')
self.cancel_button=Button(top,text="Cancel",
command=self.cancel,
state=DISABLED)
self.cancel_button.grid(row=2,column=2,sticky='w')
self.auto_button=Button(top,text="Paste+Go",
command=self.auto)
self.auto_button.grid(row=2,column=3,sticky='w')
self.status_label=Label(top,text="[idle]")
self.status_label.grid(row=2,column=4,sticky='w')
self.top.update_idletasks()
self.top.grid_propagate(0)
def message(self,text,*args):
if args:
text=text % args
self.status_label.config(text=text)
def check_msgq(self):
while not self.msgq.empty():
msg=self.msgq.get()
if msg is None:
self.go_button.configure(state=NORMAL)
self.auto_button.configure(state=NORMAL)
self.cancel_button.configure(state=DISABLED)
if self.sucker:
self.sucker.stopit=0
self.top.bell()
else:
self.message(msg)
self.top.after(100,self.check_msgq)
def go(self,event=None):
if not self.msgq:
self.msgq=Queue.Queue(0)
self.check_msgq()
if not self.sucker:
self.sucker=SuckerThread(self.msgq)
if self.sucker.stopit:
return
self.url_entry.selection_range(0,END)
url=self.url_entry.get()
url=url.strip()
if not url:
self.top.bell()
self.message("[Error: No URL entered]")
return
self.rooturl=url
dir=self.dir_entry.get().strip()
if not dir:
self.sucker.savedir=None
else:
self.sucker.savedir=dir
self.sucker.rootdir=os.path.dirname(
websucker.Sucker.savefilename(self.sucker,url))
self.go_button.configure(state=DISABLED)
self.auto_button.configure(state=DISABLED)
self.cancel_button.configure(state=NORMAL)
self.message( '[running...]')
self.sucker.stopit=0
t=threading.Thread(target=self.sucker.run1,args=(url,))
t.start()
def cancel(self):
if self.sucker:
self.sucker.stopit=1
self.message("[canceling...]")
def auto(self):
tries=['PRIMARY','CLIPBOARD']
text=""
for t in tries:
try:
text=self.top.selection_get(selection=t)
except TclError:
continue
text=text.strip()
if text:
break
if not text:
self.top.bell()
self.message("[Error: clipboard is empty]")
return
self.url_entry.delete(0,END)
self.url_entry.insert(0,text)
self.go()
class AppArray:
def __init__(self,top=None):
if not top:
top=Tk()
top.title("websucker GUI")
top.iconname("wsgui")
top.wm_protocol('WM_DELETE_WINDOW',self.exit)
self.top=top
self.appframe=Frame(self.top)
self.appframe.pack(fill='both')
self.applist=[]
self.exit_button=Button(top,text="Exit",command=self.exit)
self.exit_button.pack(side=RIGHT)
self.new_button=Button(top,text="New",command=self.addsucker)
self.new_button.pack(side=LEFT)
self.addsucker()
##self.applist[0].url_entry.insert(END,"http://www.python.org/doc/essays/")
def addsucker(self):
self.top.geometry("")
frame=Frame(self.appframe,borderwidth=2,relief=GROOVE)
frame.pack(fill='x')
app=App(frame)
self.applist.append(app)
done=0
def mainloop(self):
while not self.done:
time.sleep(0.1)
self.top.update()
def exit(self):
for app in self.applist:
app.cancel()
app.message("[exiting...]")
self.done=1
def main():
AppArray().mainloop()
if __name__ == '__main__':
main()

View File

@ -0,0 +1,33 @@
require 'inifile'
# Reads settings from init file
class Settings
attr_reader :jusername, :jpassword, :jurl
def initialize(path)
settings = read(path)
parse(settings)
end
private
def read(path)
settings = IniFile.load(path)
fail "File #{path} not found!" unless settings
settings
end
def parse(settings)
jira = settings['jira']
fail "Init file hasn't [jira] section!" unless jira
@jusername = jira['username']
@jpassword = jira['password']
@jurl = jira['url']
fail "Init file hasn't username option!" unless jusername
fail "Init file hasn't password option!" unless jpassword
fail "Init file hasn't url option!" unless jurl
end
end

View File

@ -0,0 +1 @@
body{overflow:hidden;background:#000000;background-image:url(images/bg.gif);background-repeat:no-repeat;background-position:left top;}

View File

@ -0,0 +1,4 @@
{
"test": "test",
"test": [1, 2, 3]
}

View File

@ -0,0 +1 @@
selECT * FROM foo WHERE id IN (SELECT id FROM bar);

View File

@ -0,0 +1 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title> </title></head><body> <script type="text/javascript">function bla(foo) { }</script><br /> <form> <input type="text" name="NUMBER" onkeypress= "RETURN ISnUMBERkEY(EVENT)" /> </form></body></html>

View File

@ -0,0 +1 @@
<catalog> <book id="bk101"> <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description>An in-depth look at creating applications with XML.</description> </book> <book id="bk102"> <author>Ralls, Kim</author> <title>Midnight Rain</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2000-12-16</publish_date> <description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description> </book> <book id="bk103"> <author>Corets, Eva</author> <title>Maeve Ascendant</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2000-11-17</publish_date> <description>After the collapse of a nanotechnology society in England, the young survivors lay the foundation for a new society.</description> </book> <book id="bk104"> <author>Corets, Eva</author> <title>Oberon's Legacy</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2001-03-10</publish_date> <description>In post-apocalypse England, the mysterious agent known only as Oberon helps to create a new life for the inhabitants of London. Sequel to Maeve Ascendant.</description> </book> <book id="bk105"> <author>Corets, Eva</author> <title>The Sundered Grail</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2001-09-10</publish_date> <description>The two daughters of Maeve, half-sisters, battle one another for control of England. Sequel to Oberon's Legacy.</description> </book> <book id="bk106"> <author>Randall, Cynthia</author> <title>Lover Birds</title> <genre>Romance</genre> <price>4.95</price> <publish_date>2000-09-02</publish_date> <description>When Carla meets Paul at an ornithology conference, tempers fly as feathers get ruffled.</description> </book> <book id="bk107"> <author>Thurman, Paula</author> <title>Splish Splash</title> <genre>Romance</genre> <price>4.95</price> <publish_date>2000-11-02</publish_date> <description>A deep sea diver finds true love twenty thousand leagues beneath the sea.</description> </book> <book id="bk108"> <author>Knorr, Stefan</author> <title>Creepy Crawlies</title> <genre>Horror</genre> <price>4.95</price> <publish_date>2000-12-06</publish_date> <description>An anthology of horror stories about roaches, centipedes, scorpions and other insects.</description> </book> <book id="bk109"> <author>Kress, Peter</author> <title>Paradox Lost</title> <genre>Science Fiction</genre> <price>6.95</price> <publish_date>2000-11-02</publish_date> <description>After an inadvertant trip through a Heisenberg Uncertainty Device, James Salway discovers the problems of being quantum.</description> </book> <book id="bk110"> <author>O'Brien, Tim</author> <title>Microsoft .NET: The Programming Bible</title> <genre>Computer</genre> <price>36.95</price> <publish_date>2000-12-09</publish_date> <description>Microsoft's .NET initiative is explored in detail in this deep programmer's reference.</description> </book> <book id="bk111"> <author>O'Brien, Tim</author> <title>MSXML3: A Comprehensive Guide</title> <genre>Computer</genre> <price>36.95</price> <publish_date>2000-12-01</publish_date> <description>The Microsoft MSXML3 parser is covered in detail, with attention to XML DOM interfaces, XSLT processing, SAX and more.</description> </book> <book id="bk112"> <author>Galos, Mike</author> <title>Visual Studio 7: A Comprehensive Guide</title> <genre>Computer</genre> <price>49.95</price> <publish_date>2001-04-16</publish_date> <description>Microsoft Visual Studio 7 is explored in depth, looking at how Visual Basic, Visual C++, C#, and ASP+ are integrated into a comprehensive development environment.</description> </book></catalog>