diff options
-rw-r--r-- | runtime/doc/autocmd.txt | 17 | ||||
-rw-r--r-- | runtime/doc/editing.txt | 25 | ||||
-rw-r--r-- | runtime/doc/eval.txt | 64 | ||||
-rw-r--r-- | runtime/doc/intro.txt | 11 | ||||
-rw-r--r-- | runtime/doc/motion.txt | 6 | ||||
-rw-r--r-- | runtime/doc/options.txt | 22 | ||||
-rw-r--r-- | runtime/doc/tags | 9 | ||||
-rw-r--r-- | runtime/doc/usr_41.txt | 475 | ||||
-rw-r--r-- | runtime/doc/usr_toc.txt | 13 | ||||
-rw-r--r-- | runtime/doc/various.txt | 5 | ||||
-rw-r--r-- | runtime/syntax/vim.vim | 2 | ||||
-rw-r--r-- | src/edit.c | 10 | ||||
-rw-r--r-- | src/ex_cmds2.c | 11 | ||||
-rw-r--r-- | src/ex_docmd.c | 8 | ||||
-rw-r--r-- | src/ex_getln.c | 9 | ||||
-rw-r--r-- | src/fileio.c | 14 | ||||
-rw-r--r-- | src/gui_motif.c | 79 | ||||
-rw-r--r-- | src/gui_xmebw.c | 19 | ||||
-rw-r--r-- | src/move.c | 3 | ||||
-rw-r--r-- | src/ops.c | 92 | ||||
-rw-r--r-- | src/option.c | 11 | ||||
-rw-r--r-- | src/option.h | 3 | ||||
-rw-r--r-- | src/os_unix.c | 3 | ||||
-rw-r--r-- | src/proto/gui_motif.pro | 1 | ||||
-rw-r--r-- | src/quickfix.c | 65 | ||||
-rw-r--r-- | src/structs.h | 1 | ||||
-rw-r--r-- | src/version.h | 4 | ||||
-rw-r--r-- | src/vim.h | 2 |
28 files changed, 795 insertions, 189 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index 2b7edf5ec..c815f362a 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -1,4 +1,4 @@ -*autocmd.txt* For Vim version 7.0aa. Last change: 2005 Jan 26 +*autocmd.txt* For Vim version 7.0aa. Last change: 2005 Feb 07 VIM REFERENCE MANUAL by Bram Moolenaar @@ -324,6 +324,7 @@ FuncUndefined When a user function is used but it isn't defined. Useful for defining a function only when it's used. Both <amatch> and <afile> are set to the name of the function. + See |autoload-functions|. *CursorHold* CursorHold When the user doesn't press a key for the time specified with 'updatetime'. Not re-triggered @@ -520,6 +521,20 @@ TermResponse After the response to |t_RV| is received from the terminal. The value of |v:termresponse| can be used to do things depending on the terminal version. +QuickFixCmdPre *QuickFixCmdPre* + Before a quickfix command is run (|:make|, + |:grep|, |:grepadd|, |:vimgrep|, + |:vimgrepadd|). The pattern is matched against + the command being run. When |:grep| is used + but 'grepprg' is set to "internal" it still + matches "grep". + This command cannot be used to set the + 'makeprg' and 'grepprg' variables. + If this command causes an error, the quickfix + command is not executed. +QuickFixCmdPost *QuickFixCmdPost* + like QuickFixCmdPre, but after a quickfix + command is run. *UserGettingBored* UserGettingBored When the user hits CTRL-C. Just kidding! :-) *User* diff --git a/runtime/doc/editing.txt b/runtime/doc/editing.txt index e5acbb921..ae7543e8d 100644 --- a/runtime/doc/editing.txt +++ b/runtime/doc/editing.txt @@ -1,4 +1,4 @@ -*editing.txt* For Vim version 7.0aa. Last change: 2005 Jan 26 +*editing.txt* For Vim version 7.0aa. Last change: 2005 Feb 07 VIM REFERENCE MANUAL by Bram Moolenaar @@ -69,18 +69,21 @@ CTRL-G or *CTRL-G* *:f* *:fi* *:file* buffer number is also given. {not in Vi} *g_CTRL-G* *word-count* *byte-count* -g CTRL-G Prints the current position of the cursor in four - ways: Column, Line, Word and Byte. If there are - characters in the line that take more than one - position on the screen (<Tab> or special character), - both the "real" column and the screen column are - shown, separated with a dash. See also 'ruler' - option. {not in Vi} +g CTRL-G Prints the current position of the cursor in five + ways: Column, Line, Word, Character and Byte. If the + number of Characters and Bytes is the same then the + Character position is omitted. + If there are characters in the line that take more + than one position on the screen (<Tab> or special + character), both the "real" column and the screen + column are shown, separated with a dash. + See also 'ruler' option. {not in Vi} *v_g_CTRL-G* -{Visual}g CTRL-G Similar to "g CTRL-G", but Word, Line, and Byte counts - for the visually selected region are displayed. In - Blockwise mode, Column count is also shown. (For +{Visual}g CTRL-G Similar to "g CTRL-G", but Word, Character, Line, and + Byte counts for the visually selected region are + displayed. + In Blockwise mode, Column count is also shown. (For {Visual} see |Visual-mode|.) {not in VI} diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index c0031e853..450408c81 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1,4 +1,4 @@ -*eval.txt* For Vim version 7.0aa. Last change: 2005 Feb 05 +*eval.txt* For Vim version 7.0aa. Last change: 2005 Feb 07 VIM REFERENCE MANUAL by Bram Moolenaar @@ -15,7 +15,7 @@ done, the features in this document are not available. See |+eval| and 1. Variables |variables| 1.1 Variable types 1.2 Function references |Funcref| - 1.3 Lists |List| + 1.3 Lists |Lists| 1.4 Dictionaries |Dictionaries| 1.5 More about variables |more-variables| 2. Expression syntax |expression-syntax| @@ -126,7 +126,7 @@ arguments: > 1.3 Lists ~ - *List* *E686* + *List* *Lists* *E686* A List is an ordered sequence of items. An item can be of any type. Items can be accessed by their index number. Items can be added and removed at any position in the sequence. @@ -410,7 +410,7 @@ a List in which each item is a List with two items, the key and the value: > Dictionary identity ~ - + *dict-identity* Just like Lists you need to use |copy()| and |deepcopy()| to make a copy of a Dictionary. Otherwise, assignment results in referring to the same Dictionary: > @@ -1362,6 +1362,7 @@ USAGE RESULT DESCRIPTION ~ add( {list}, {item}) List append {item} to List {list} append( {lnum}, {string}) Number append {string} below line {lnum} +append( {lnum}, {list}) Number append lines {list} below line {lnum} argc() Number number of files in the argument list argidx() Number current index in the argument list argv( {nr}) String {nr} entry of the argument list @@ -1429,7 +1430,8 @@ getfsize( {fname}) Number size in bytes of file {fname} getfontname( [{name}]) String name of font being used getftime( {fname}) Number last modification time of file getftype( {fname}) String description of type of file {fname} -getline( {lnum}) String line {lnum} from current buffer +getline( {lnum}) String line {lnum} of current buffer +getline( {lnum}, {end}) List lines {lnum} to {end} of current buffer getreg( [{regname}]) String contents of register getregtype( [{regname}]) String type of register getwinposx() Number X coord in pixels of GUI Vim window @@ -4342,16 +4344,64 @@ the caller to set the names. The recursiveness of user functions is restricted with the |'maxfuncdepth'| option. + +AUTOMATICALLY LOADING FUNCTIONS ~ *autoload-functions* When using many or large functions, it's possible to automatically define them -only when they are used. Use the FuncUndefined autocommand event with a -pattern that matches the function(s) to be defined. Example: > +only when they are used. There are two methods: with an autocommand and with +the "autoload" directory in 'runtimepath'. + + +Using an autocommand ~ + +The autocommand is useful if you have a plugin that is a long Vim script file. +You can define the autocommand and quickly quit the script with |:finish|. +That makes Vim startup faster. The autocommand should then load the same file +again, setting a variable to skip the |:finish| command. + +Use the FuncUndefined autocommand event with a pattern that matches the +function(s) to be defined. Example: > :au FuncUndefined BufNet* source ~/vim/bufnetfuncs.vim The file "~/vim/bufnetfuncs.vim" should then define functions that start with "BufNet". Also see |FuncUndefined|. + +Using an autoload script ~ + +Using a script in the "autoload" directory is simpler, but requires using +exactly the right file name. A function that can be autoloaded has a name +like this: > + + :call filename:funcname() + +When such a function is called, and it is not defined yet, Vim will search the +"autoload" directories in 'runtimepath' for a script file called +"filename.vim". For example "~/.vim/autoload/filename.vim". That file should +then define the function like this: > + + function filename:funcname() + echo "Done!" + endfunction + +The file name and the name used before the colon in the function must match +exactly, and the defined function must have the name exactly as it will be +called. + +It is possible to use subdirectories. Every colon in the function name works +like a path separator. Thus when calling a function: > + + :call foo:bar:func() + +Vim will look for the file "autoload/foo/bar.vim" in 'runtimepath'. + +The name before the first colon must be at least two characters long, +otherwise it looks like a scope, such as "s:". + +Note that the script will be sourced again and again if a function is called +that looks like it is defined in the autoload script but it isn't. + ============================================================================== 6. Curly braces names *curly-braces-names* diff --git a/runtime/doc/intro.txt b/runtime/doc/intro.txt index d984ce259..935577724 100644 --- a/runtime/doc/intro.txt +++ b/runtime/doc/intro.txt @@ -1,4 +1,4 @@ -*intro.txt* For Vim version 7.0aa. Last change: 2004 Dec 16 +*intro.txt* For Vim version 7.0aa. Last change: 2005 Feb 07 VIM REFERENCE MANUAL by Bram Moolenaar @@ -289,8 +289,7 @@ Vi "the original". Without further remarks this is the version Posix From the IEEE standard 1003.2, Part 2: Shell and utilities. Generally known as "Posix". This is a textual description of how Vi is supposed to work. - The version used is a draft from beginning 1996, so all remarks are - "expected to comply to" this. Anything can change though... + See |posix-compliance|. *Nvi* Nvi The "New" Vi. The version of Vi that comes with BSD 4.4 and FreeBSD. Very good compatibility with the original Vi, with a few extensions. @@ -691,9 +690,9 @@ Q Switch to "Ex" mode. This is a bit like typing ":" |vimrc_example.vim| script "Q" works like "gq". *gQ* -gQ Switch to "Ex" mode, but really behave like typing ":" - commands after another. All command line editing, - completion etc. is available. +gQ Switch to "Ex" mode like with "Q", but really behave + like typing ":" commands after another. All command + line editing, completion etc. is available. Use the ":vi" command |:visual| to exit "Ex" mode. {not in Vi} diff --git a/runtime/doc/motion.txt b/runtime/doc/motion.txt index bee238e5e..daaa6020e 100644 --- a/runtime/doc/motion.txt +++ b/runtime/doc/motion.txt @@ -1,4 +1,4 @@ -*motion.txt* For Vim version 7.0aa. Last change: 2005 Jan 08 +*motion.txt* For Vim version 7.0aa. Last change: 2005 Feb 07 VIM REFERENCE MANUAL by Bram Moolenaar @@ -350,6 +350,10 @@ or the last line. The first two commands put the cursor in the same column except after the "$" command, then the cursor will be put on the last character of the line. +If "k", "-" or CTRL-P is used with a [count] and there are less than [count] +lines above the cursor and the 'cpo' option includes the "-" flag it is an +error. |cpo--|. + ============================================================================== 4. Word motions *word-motions* diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index d79aab72e..e1c6f5ae4 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -1,4 +1,4 @@ -*options.txt* For Vim version 7.0aa. Last change: 2005 Jan 30 +*options.txt* For Vim version 7.0aa. Last change: 2005 Feb 07 VIM REFERENCE MANUAL by Bram Moolenaar @@ -1382,7 +1382,8 @@ A jump table for the options with a short description can be found at |Q_op|. global {not in Vi} Number of columns of the screen. Normally this is set by the terminal - initialization and does not have to be set by hand. + initialization and does not have to be set by hand. Also see + |posix-screen-size|. When Vim is running in the GUI or in a resizable window, setting this option will cause the window size to be changed. When you only want to use the size for the GUI, put the command in your |gvimrc| file. @@ -1431,7 +1432,7 @@ A jump table for the options with a short description can be found at |Q_op|. to the Vim defaults. Effectively, this means that when a ".vimrc" file exists, Vim will use the Vim defaults, otherwise it will use the Vi defaults. (Note: This doesn't happen for the system-wide vimrc - file). Also see |compatible-default|. + file). Also see |compatible-default| and |posix-compliance|. You can also set this option with the "-C" argument, and reset it with "-N". See |-C| and |-N|. Switching this option off makes the Vim defaults be used for options @@ -1844,6 +1845,13 @@ A jump table for the options with a short description can be found at |Q_op|. there is one). This works very well for C programs. This flag is also used for other features, such as C-indenting. + *cpo--* + - When included, a vertical movement command fails when + it would above the first line or below the last line. + Without it the cursor moves to the first or last line, + unless it already was in that line. + Applies to the commands "-", "k", CTRL-P, "+", "j", + CTRL-N and CTRL-J. *cpo-+* + When included, a ":write file" command will reset the 'modified' flag of the buffer, even though the buffer @@ -2804,7 +2812,7 @@ A jump table for the options with a short description can be found at |Q_op|. VMS: "SEARCH/NUMBERS ") global or local to buffer |global-local| {not in Vi} - Program to use for the ":grep" command. This option may contain '%' + Program to use for the |:grep| command. This option may contain '%' and '#' characters, which are expanded like when used in a command- line. The placeholder "$*" is allowed to specify where the arguments will be included. Environment variables are expanded |:set_env|. See @@ -2812,8 +2820,8 @@ A jump table for the options with a short description can be found at |Q_op|. When your "grep" accepts the "-H" argument, use this to make ":grep" also work well with a single file: > :set grepprg=grep\ -nH -< Special value: When 'grepprg' is set to "internal" the ":grep" works - like ":vimgrep". +< Special value: When 'grepprg' is set to "internal" the |:grep| command + works like |:vimgrep| and |:grepadd| like |:vimgrepadd|. See also the section |:make_makeprg|, since most of the comments there apply equally to 'grepprg'. For Win32, the default is "findstr /n" if "findstr.exe" can be found, @@ -3882,7 +3890,7 @@ A jump table for the options with a short description can be found at |Q_op|. global Number of lines of the Vim window. Normally you don't need to set this. It is done automatically by the - terminal initialization code. + terminal initialization code. Also see |posix-screen-size|. When Vim is running in the GUI or in a resizable window, setting this option will cause the window size to be changed. When you only want to use the size for the GUI, put the command in your |gvimrc| file. diff --git a/runtime/doc/tags b/runtime/doc/tags index 8ad645313..30611f86f 100644 --- a/runtime/doc/tags +++ b/runtime/doc/tags @@ -1531,6 +1531,7 @@ $VIMRUNTIME starting.txt /*$VIMRUNTIME* 41.10 usr_41.txt /*41.10* 41.11 usr_41.txt /*41.11* 41.12 usr_41.txt /*41.12* +41.13 usr_41.txt /*41.13* 41.2 usr_41.txt /*41.2* 41.3 usr_41.txt /*41.3* 41.4 usr_41.txt /*41.4* @@ -3738,6 +3739,7 @@ Korean mbyte.txt /*Korean* L motion.txt /*L* Linux-backspace options.txt /*Linux-backspace* List eval.txt /*List* +Lists eval.txt /*Lists* M motion.txt /*M* MDI starting.txt /*MDI* MS-DOS os_msdos.txt /*MS-DOS* @@ -3833,6 +3835,8 @@ Q_vi quickref.txt /*Q_vi* Q_vm quickref.txt /*Q_vm* Q_wi quickref.txt /*Q_wi* Q_wq quickref.txt /*Q_wq* +QuickFixCmdPost autocmd.txt /*QuickFixCmdPost* +QuickFixCmdPre autocmd.txt /*QuickFixCmdPre* Quickfix quickfix.txt /*Quickfix* R change.txt /*R* RISC-OS os_risc.txt /*RISC-OS* @@ -4378,6 +4382,7 @@ cpo-! options.txt /*cpo-!* cpo-$ options.txt /*cpo-$* cpo-% options.txt /*cpo-%* cpo-+ options.txt /*cpo-+* +cpo-- options.txt /*cpo--* cpo-< options.txt /*cpo-<* cpo-A options.txt /*cpo-A* cpo-B options.txt /*cpo-B* @@ -4524,6 +4529,7 @@ diW motion.txt /*diW* dialog gui_w32.txt /*dialog* dialogs-added version5.txt /*dialogs-added* dib motion.txt /*dib* +dict-identity eval.txt /*dict-identity* dict-modification eval.txt /*dict-modification* did_filetype() eval.txt /*did_filetype()* diff diff.txt /*diff* @@ -5460,6 +5466,7 @@ match() eval.txt /*match()* match-highlight pattern.txt /*match-highlight* matchend() eval.txt /*matchend()* matchit-install usr_05.txt /*matchit-install* +matchlist() eval.txt /*matchlist()* matchstr() eval.txt /*matchstr()* max() eval.txt /*max()* mbyte-IME mbyte.txt /*mbyte-IME* @@ -5830,6 +5837,8 @@ popup-menu gui.txt /*popup-menu* popup-menu-added version5.txt /*popup-menu-added* ports-5.2 version5.txt /*ports-5.2* ports-6 version6.txt /*ports-6* +posix-compliance vi_diff.txt /*posix-compliance* +posix-screen-size vi_diff.txt /*posix-screen-size* postscr-syntax syntax.txt /*postscr-syntax* postscr.vim syntax.txt /*postscr.vim* postscript-cjk-printing print.txt /*postscript-cjk-printing* diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt index d90c24abf..74c74fdb7 100644 --- a/runtime/doc/usr_41.txt +++ b/runtime/doc/usr_41.txt @@ -1,4 +1,4 @@ -*usr_41.txt* For Vim version 7.0aa. Last change: 2005 Feb 04 +*usr_41.txt* For Vim version 7.0aa. Last change: 2005 Feb 07 VIM USER MANUAL - by Bram Moolenaar @@ -16,11 +16,12 @@ script. There are a lot of them, thus this is a long chapter. |41.5| Executing an expression |41.6| Using functions |41.7| Defining a function -|41.8| Exceptions -|41.9| Various remarks -|41.10| Writing a plugin -|41.11| Writing a filetype plugin -|41.12| Writing a compiler plugin +|41.8| Lists and Dictionaries +|41.9| Exceptions +|41.10| Various remarks +|41.11| Writing a plugin +|41.12| Writing a filetype plugin +|41.13| Writing a compiler plugin Next chapter: |usr_42.txt| Add new menus Previous chapter: |usr_40.txt| Make new commands @@ -42,7 +43,7 @@ Let's start with a simple example: > :let i = 1 :while i < 5 : echo "count is" i - : let i = i + 1 + : let i += 1 :endwhile < Note: @@ -50,8 +51,19 @@ Let's start with a simple example: > them when you type a command. In a Vim script file they can be left out. We will use them here anyway to make clear these are colon commands and make them stand out from Normal mode commands. + Note: + You can try out the examples by yanking the lines from the text here + and executing them with :@" + +The output of the example code is: + + count is 1 ~ + count is 2 ~ + count is 3 ~ + count is 4 ~ -The ":let" command assigns a value to a variable. The generic form is: > +In the first line the ":let" command assigns a value to a variable. The +generic form is: > :let {variable} = {expression} @@ -66,61 +78,52 @@ the number one. The statements until the matching ":endwhile" are executed for as long as the condition is true. The condition used here is the expression "i < 5". This is true when the variable i is smaller than five. - The ":echo" command prints its arguments. In this case the string "count -is" and the value of the variable i. Since i is one, this will print: - - count is 1 ~ + Note: + If you happen to write a while loop that keeps on running, you can + interrupt it by pressing CTRL-C (CTRL-Break on MS-Windows). -Then there is another ":let i =" command. The value used is the expression "i -+ 1". This adds one to the variable i and assigns the new value to the same -variable. - The output of the example code is: +The ":echo" command prints its arguments. In this case the string "count is" +and the value of the variable i. Since i is one, this will print: count is 1 ~ - count is 2 ~ - count is 3 ~ - count is 4 ~ - Note: - If you happen to write a while loop that keeps on running, you can - interrupt it by pressing CTRL-C (CTRL-Break on MS-Windows). - Note: - You can try out the examples by yanking the lines from the text here - and executing them with :@" +Then there is the ":let i += 1" command. This does the same thing as +":let i = i + 1". This adds one to the variable i and assigns the new value +to the same variable. -The example was given to explain the commands, but you would really want to +The example was given to explain the commands, but would you really want to make such a loop it can be written much more compact: > :for i in range(1, 4) : echo "count is" i :endfor -We won't explain how |:for| and |range()| work right now. Follow the links if -you are impatient. +We won't explain how |:for| and |range()| work until later. Follow the links +if you are impatient. THREE KINDS OF NUMBERS Numbers can be decimal, hexadecimal or octal. A hexadecimal number starts -with "0x" or "0X". For example "0x1f" is 31. An octal number starts with a -zero. "017" is 15. Careful: don't put a zero before a decimal number, it -will be interpreted as an octal number! +with "0x" or "0X". For example "0x1f" is decimal 31. An octal number starts +with a zero. "017" is decimal 15. Careful: don't put a zero before a decimal +number, it will be interpreted as an octal number! The ":echo" command always prints decimal numbers. Example: > :echo 0x7f 036 < 127 30 ~ A number is made negative with a minus sign. This also works for hexadecimal -and octal numbers. A minus sign is also for subtraction. Compare this with -the previous example: > +and octal numbers. A minus sign is also used for subtraction. Compare this +with the previous example: > :echo 0x7f -036 < 97 ~ White space in an expression is ignored. However, it's recommended to use it for separating items, to make the expression easier to read. For example, to -avoid the confusion with a negative number, put a space between the minus sign -and the following number: > +avoid the confusion with a negative number above, put a space between the +minus sign and the following number: > :echo 0x7f - 036 @@ -151,7 +154,7 @@ example, one script contains this code: > :let s:count = 1 :while s:count < 5 : source other.vim - : let s:count = s:count + 1 + : let s:count += 1 :endwhile Since "s:count" is local to this script, you can be sure that sourcing the @@ -202,15 +205,21 @@ exists() checks. That's not what you want. The exclamation mark ! negates a value. When the value was true, it becomes false. When it was false, it becomes true. You can read it as "not". Thus "if !exists()" can be read as "if not exists()". - What Vim calls true is anything that is not zero. Only zero is false. + What Vim calls true is anything that is not zero. Zero is false. + Note: + Vim automatically converts a string to a number when it is looking for + a number. When using a string that doesn't start with a digit the + resulting number is zero. Thus look out for this: > + :if "true" +< The "true" will be interpreted as a zero, thus as false! STRING VARIABLES AND CONSTANTS So far only numbers were used for the variable value. Strings can be used as -well. Numbers and strings are the only two types of variables that Vim -supports. The type is dynamic, it is set each time when assigning a value to -the variable with ":let". +well. Numbers and strings are the basic types of variables that Vim supports. +The type is dynamic, it is set each time when assigning a value to the +variable with ":let". More about types in |41.8|. To assign a string value to a variable, you need to use a string constant. There are two types of these. First the string in double quotes: > @@ -231,9 +240,9 @@ To avoid the need for a backslash, you can use a string in single quotes: > :echo name < "peter" ~ -Inside a single-quote string all the characters are as they are. The drawback -is that it's impossible to include a single quote. A backslash is taken -literally as well, thus you can't use it to change the meaning of the +Inside a single-quote string all the characters are as they are. Only the +single quote itself is special: you need to use two to get one. A backslash +is taken literally, thus you can't use it to change the meaning of the character after it. In double-quote strings it is possible to use special characters. Here are a few useful ones: @@ -281,7 +290,8 @@ do something and restore the old value. Example: > :let &ic = save_ic This makes sure the "The Start" pattern is used with the 'ignorecase' option -off. Still, it keeps the value that the user had set. +off. Still, it keeps the value that the user had set. (Another way to do +this would be to add "\C" to the pattern, see |/\C|.) MATHEMATICS @@ -387,7 +397,7 @@ ones: The result is one if the condition is met and zero otherwise. An example: > - :if v:version >= 600 + :if v:version >= 700 : echo "congratulations" :else : echo "you are using an old version, upgrade!" @@ -428,8 +438,8 @@ pattern, like what's used for searching. Example: > :endif Notice the use of a single-quote string for the pattern. This is useful, -because backslashes need to be doubled in a double-quote string and patterns -tend to contain many backslashes. +because backslashes would need to be doubled in a double-quote string and +patterns tend to contain many backslashes. The 'ignorecase' option is used when comparing strings. When you don't want that, append "#" to match case and "?" to ignore case. Thus "==?" compares @@ -464,6 +474,8 @@ Example: > The ":sleep" command makes Vim take a nap. The "50m" specifies fifty milliseconds. Another example is ":sleep 4", which sleeps for four seconds. +Even more looping can be done with the ":for" command, see below in |41.8|. + ============================================================================== *41.5* Executing an expression @@ -503,6 +515,17 @@ This inserts "new text " in the current line. Notice the use of the special key "\<Esc>". This avoids having to enter a real <Esc> character in your script. +If you don't want to execute a string but evaluate it to get its expression +value, you can use the eval() function: > + + :let optname = "path" + :let optval = eval('&' . optname) + +A "&" character is prepended to "path", thus the argument to eval() is +"&path". The result will then be the value of the 'path' option. + The same thing can be done with: > + :exe 'let optval = &' . optname + ============================================================================== *41.6* Using functions @@ -526,9 +549,9 @@ A function can be called in an expression. Example: > :let repl = substitute(line, '\a', "*", "g") :call setline(".", repl) -The getline() function obtains a line from the current file. Its argument is -a specification of the line number. In this case "." is used, which means the -line where the cursor is. +The getline() function obtains a line from the current buffer. Its argument +is a specification of the line number. In this case "." is used, which means +the line where the cursor is. The substitute() function does something similar to the ":substitute" command. The first argument is the string on which to perform the substitution. The second argument is the pattern, the third the replacement @@ -567,7 +590,6 @@ String manipulation: submatch() get a specific match in a ":substitute" strpart() get part of a string expand() expand special keywords - type() type of a variable iconv() convert text from one encoding to another List manipulation: @@ -588,11 +610,10 @@ List manipulation: join() join List items into a String string() String representation of a List call() call a function with List as arguments + index() index of a value in a list max() maximum value in a List min() minimum value in a List count() count number of times a value appears in a List - getline() get List with buffer lines - append() append List of lines to the buffer Dictionary manipulation: get() get an entries without error for wrong key @@ -622,9 +643,9 @@ Working with text in the current buffer: wincol() window column number of the cursor winline() window line number of the cursor cursor() position the cursor at a line/column - getline() get a line from the buffer + getline() get a line or list of lines from the buffer setline() replace a line in the buffer - append() append {string} below line {lnum} + append() append line or list of lines in the buffer indent() indent of a specific line cindent() indent according to C indenting lispindent() indent according to Lisp indenting @@ -713,6 +734,7 @@ Vim server: remote_foreground() move the Vim server window to the foreground Various: + type() type of a variable mode() get current editing mode visualmode() last visual mode used hasmapto() check if a mapping exists @@ -792,6 +814,15 @@ The complete function definition is as follows: > : return smaller :endfunction +For people who like short functions, this does the same thing: > + + :function Min(num1, num2) + : if a:num1 < a:num2 + : return a:num1 + : endif + : return a:num2 + :endfunction + A user defined function is called in exactly the same way as a builtin function. Only the name is different. The Min function can be used like this: > @@ -879,6 +910,9 @@ This uses the ":echohl" command to specify the highlighting used for the following ":echo" command. ":echohl None" stops it again. The ":echon" command works like ":echo", but doesn't output a line break. +You can also use the a:000 variable, it is a List of all the "..." arguments. +See |a:000|. + LISTING FUNCTIONS @@ -915,8 +949,327 @@ To delete the Show() function: > You get an error when the function doesn't exist. + +FUNCTION REFERENCES + +Sometimes it can be useful to have a variable point to one function or +another. You can do it with the function() function. It turns the name of a +function into a reference: > + + :let result = 0 " or 1 + :function! Right() + : return 'Right!' + :endfunc + :function! Wrong() + : return 'Wrong!' + :endfunc + : + :if result == 1 + : let Afunc = function('Right') + :else + : let Afunc = function('Wrong') + :endif + :echo call(Afunc, []) +< Wrong! ~ + +Note that the name of a variable that holds a function reference must start +with a capital. Otherwise it could be confused with the name of a builtin +function. + The way to invoke a function that a variable refers to is with the call() +function. Its first argument is the function reference, the second argument +is a List with arguments. + +Function references are most useful in combination with a Dictionary, as is +explained in the next section. + +============================================================================== +*41.8* Lists and Dictionaries + +So far we have used the basic types String and Number. Vim also supports two +composite types: List and Dictionary. + +A List is an ordered sequence of things. The things can be any kind of value, +thus you can make a List of numbers, a List of Lists and even a List of mixed +items. To create a List with three strings: > + + :let alist = ['aap', 'mies', 'noot'] + +The List items are enclosed in square brackets and separated by commas. To +create an empty List: > + + :let alist = [] + +You can add items to a List with the add() function: > + + :let alist = [] + :call add(alist, 'foo') + :call add(alist, 'bar') + :echo alist +< ['foo', 'bar'] ~ + +List concatenation is done with +: > + + :echo alist + ['foo', 'bar'] +< ['foo', 'bar', 'foo', 'bar'] ~ + +Or, if you want to extend a List directly: > + + :let alist = ['one'] + :call extend(alist, ['two', 'three']) + :echo alist +< ['one', 'two', 'three'] ~ + +Notice that using add() will have a different effect: > + + :let alist = ['one'] + :call add(alist, ['two', 'three']) + :echo alist +< ['one', ['two', 'three']] ~ + +The second argument of add() is added as a single item. + + +FOR LOOP + +One of the nice things you can do with a List is iterate over it: > + + :let alist = ['one', 'two', 'three'] + :for n in alist + : echo n + :endfor +< one ~ + two ~ + three ~ + +This will loop over each element in List "alist", assigning the value to +variable "n". The generic form of a for loop is: > + + :for {varname} in {listexpression} + : {commands} + :endfor + +To loop a certain number of times you need a List of a specific length. The +range() function creates one for you: > + + :for a in range(3) + : echo a + :endfor +< 0 ~ + 1 ~ + 2 ~ + +Notice that the first item of the List that range() produces is zero, thus the +last item is one less than the length of the list. + You can also specify the maximum value, the stride and even go backwards: > + + :for a in range(8, 4, -2) + : echo a + :endfor +< 8 ~ + 6 ~ + 4 ~ + +A more useful example, looping over lines in the buffer: > + + :for line in getline(1, 20) + : if line =~ "Date: " + : echo matchstr(line, 'Date: \zs.*') + : endif + :endfor + +This looks into lines 1 to 20 (inclusive) and echoes any date found in there. + + +DICTIONARIES + +A Dictionary stores key-value pairs. You can quickly lookup a value if you +know the key. A Dictionary is created with curly braces: > + + :let uk2nl = {'one': 'een', 'two': 'twee', 'three': 'drie'} + +Now you can lookup words by putting the key in square brakets: > + + :echo uk2nl['two'] +< twee ~ + +The generic form for defining a Dictionary is: > + + {<key> : <value>, ...} + +An empty Dictionary is one without any keys: > + + {} + +The possibilities with Dictionaries are numerous. There are various functions +for them as well. For example, you can obtain a list of the keys and loop +over them: > + + :for key in keys(uk2nl) + : echo key + :endfor +< three ~ + one ~ + two ~ + +The will notice the items are not ordered. You can sort the list to get a +specific order: > + + :for key in sort(keys(uk2nl)) + : echo key + :endfor +< one ~ + three ~ + two ~ + +But you can never get back the order in which items are defined. For that you +need to use a List, it stores items in an ordered sequence. + + +DICTIONARY FUNCTIONS + +The items in a Dictionary can normally be obtained with an index in square +brackets: > + + :echo uk2nl['one'] +< een ~ + +A method that does the same, but without so many punctuation characters: > + + :echo uk2nl.one +< een ~ + +This only works for a key that is made of ASCII letters, digits and the +underscore. You can also assign a new value this way: > + + :let uk2nl.four = 'vier' + :echo uk2nl +< {'three': 'drie', 'four': 'vier', 'one': 'een', 'two': 'twee'} ~ + +And now for something special: you can directly define a function and store a +reference to it in the dictionary: > + + :function uk2nl.translate(line) dict + : return join(map(split(a:line), 'get(self, v:val, "???")')) + :endfunction + +Let's first try it out: > + + :echo uk2nl.translate('three two five one') +< drie twee ??? een ~ + +The first special thing you notice is the "dict" at the end of the ":function" +line. This marks the function as being used from a Dictionary. The "self" +local variable will then refer to that Dictionary. + Now let's break up the complicated return command: > + + split(a:line) + +The split() function takes a string, chops it into white separated words +and returns a list with these words. Thus in the example it returns: > + + :echo split('three two five one') +< ['three', 'two', 'five', 'one'] ~ + +This list is the first argument to the map() function. This will go through +the list, evaluating its second argument with "v:val" set to the value of each +item. This is a shortcut to using a for loop. This command: > + + :let alist = map(split(a:line), 'get(self, v:val, "???")') + +Is equivalent to: > + + :let alist = split(a:line) + :for idx in range(len(alist)) + : let alist[idx] = get(self, alist[idx], "???") + :endfor + +The get() function checks if a key is present in a Dictionary. If it is, then +the value is retrieved. If it isn't, then the default value is returned, in +the example it's '???'. This is a covenient way to handle situations where a +key may not be present and you don't want an error message. + +The join() function does the opposite of split(): it joins together a list of +words, putting a space in between. + This combination of split(), map() and join() is a nice way to filter a line +of words in a very compact way. + + +OBJECT ORIENTED PROGRAMMING + +Now that you can put both values and functions in a Dictionary, you can +actually use a Dictionary like an object. + Above we used a Dictionary for translating Dutch to English. We might want +to do the same for other languages. Let's first make an object (aka +Dictionary) that has the translate function, but no words to translate: > + + :let transdict = {} + :function transdict.translate(line) dict + : return join(map(split(a:line), 'get(self.words, v:val, "???")')) + :endfunction + +It's slightly different from the function above, using 'self.words' to lookup +word translations. But we don't have a self.words. Thus you could call this +an abstract class. + +Now we can instantiate a Dutch translation object: > + + :let uk2nl = copy(transdict) + :let uk2nl.words = {'one': 'een', 'two': 'twee', 'three': 'drie'} + :echo uk2nl.translate('three one') +< drie een ~ + +And a German translator: > + + :let uk2de = copy(transdict) + :let uk2de.words = {'one': 'ein', 'two': 'zwei', 'three': 'drei'} + :echo uk2de.translate('three one') +< drei ein ~ + +You see that the copy() function is used to make a copy of the "transdict" +Dictionary and then the copy is changed to add the words. The original +remains the same, of course. + +Now you can go one step further, and use your preferred translator: > + + :if $LANG =~ "de" + : let trans = uk2de + :else + : let trans = uk2nl + :endif + :echo trans.translate('one two three') +< een twee drie ~ + +Here "trans" refers to one of the two objects (Dictionaries). No copy is +made. More about List and Dictionary identity can be found at |list-identity| +and |dict-identity|. + +Now you might use a language that isn't supported. You can overrule the +translate() function to do nothing: > + + :let uk2uk = copy(transdict) + :function! uk2uk.translate(line) + : return a:line + :endfunction + :echo uk2uk.translate('three one wladiwostok') +< three one wladiwostok ~ + +Notice that a ! was used to overwrite the existing function reference. Now +use "uk2uk" when no recognized language is found: > + + :if $LANG =~ "de" + : let trans = uk2de + :elseif $LANG =~ "nl" + : let trans = uk2nl + :else + : let trans = uk2uk + :endif + :echo trans.translate('one two three') +< one two three ~ + +For further reading see |Lists| and |Dictionaries|. + ============================================================================== -*41.8* Exceptions +*41.9* Exceptions Let's start with an example: > @@ -973,7 +1326,7 @@ More information about exception handling can be found in the reference manual: |exception-handling|. ============================================================================== -*41.9* Various remarks +*41.10* Various remarks Here is a summary of items that apply to Vim scripts. They are also mentioned elsewhere, but form a nice checklist. @@ -1131,7 +1484,7 @@ Example: > let XXX_loaded = 1 ============================================================================== -*41.10* Writing a plugin *write-plugin* +*41.11* Writing a plugin *write-plugin* You can write a Vim script in such a way that many people can use it. This is called a plugin. Vim users can drop your script in their plugin directory and @@ -1544,13 +1897,13 @@ hasmapto() Function to test if the user already defined a mapping exists(":Cmd") Check if a user command already exists. ============================================================================== -*41.11* Writing a filetype plugin *write-filetype-plugin* *ftplugin* +*41.12* Writing a filetype plugin *write-filetype-plugin* *ftplugin* A filetype plugin is like a global plugin, except that it sets options and defines mappings for the current buffer only. See |add-filetype-plugin| for how this type of plugin is used. -First read the section on global plugins above |41.10|. All that is said there +First read the section on global plugins above |41.11|. All that is said there also applies to filetype plugins. There are a few extras, which are explained here. The essential thing is that a filetype plugin should only have an effect on the current buffer. @@ -1730,7 +2083,7 @@ exists("*s:Func") Check if a function was already defined. Also see |plugin-special|, the special things used for all plugins. ============================================================================== -*41.12* Writing a compiler plugin *write-compiler-plugin* +*41.13* Writing a compiler plugin *write-compiler-plugin* A compiler plugin sets options for use with a specific compiler. The user can load it with the |:compiler| command. The main use is to set the diff --git a/runtime/doc/usr_toc.txt b/runtime/doc/usr_toc.txt index c371dda8f..51e8171eb 100644 --- a/runtime/doc/usr_toc.txt +++ b/runtime/doc/usr_toc.txt @@ -1,4 +1,4 @@ -*usr_toc.txt* For Vim version 7.0aa. Last change: 2003 Aug 18 +*usr_toc.txt* For Vim version 7.0aa. Last change: 2005 Feb 06 VIM USER MANUAL - by Bram Moolenaar @@ -286,11 +286,12 @@ Make Vim work as you like it. |41.5| Executing an expression |41.6| Using functions |41.7| Defining a function - |41.8| Exceptions - |41.9| Various remarks - |41.10| Writing a plugin - |41.11| Writing a filetype plugin - |41.12| Writing a compiler plugin + |41.8| Lists and Dictionaries + |41.9| Exceptions + |41.10| Various remarks + |41.11| Writing a plugin + |41.12| Writing a filetype plugin + |41.13| Writing a compiler plugin |usr_42.txt| Add new menus |42.1| Introduction diff --git a/runtime/doc/various.txt b/runtime/doc/various.txt index 84093032d..0f7947073 100644 --- a/runtime/doc/various.txt +++ b/runtime/doc/various.txt @@ -1,4 +1,4 @@ -*various.txt* For Vim version 7.0aa. Last change: 2005 Feb 04 +*various.txt* For Vim version 7.0aa. Last change: 2005 Feb 07 VIM REFERENCE MANUAL by Bram Moolenaar @@ -140,7 +140,8 @@ g8 Print the hex values of the bytes used in the The display isn't updated while ":normal" is busy. This implies that an insert command must be completed (to start Insert mode, see |:startinsert|). A ":" - command must be completed as well. + command must be completed as well. And you can't use + "Q" or "gQ" to start Ex mode. {commands} cannot start with a space. Put a 1 (one) before it, 1 space is one space. The 'insertmode' option is ignored for {commands}. diff --git a/runtime/syntax/vim.vim b/runtime/syntax/vim.vim index fe36e0ce6..60373bf90 100644 --- a/runtime/syntax/vim.vim +++ b/runtime/syntax/vim.vim @@ -44,7 +44,7 @@ syn keyword vimErrSetting contained hardtabs ht w1200 w300 w9600 wi window " AutoBuf Events {{{2 syn case ignore -syn keyword vimAutoEvent contained BufAdd BufCreate BufDelete BufEnter BufFilePost BufFilePre BufHidden BufLeave BufNew BufNewFile BufRead BufReadCmd BufReadPost BufReadPre BufUnload BufWinEnter BufWinLeave BufWipeout BufWrite BufWriteCmd BufWritePost BufWritePre Cmd-event CmdwinEnter CmdwinLeave ColorScheme CursorHold E135 E143 E200 E201 E203 E204 EncodingChanged FileAppendCmd FileAppendPost FileAppendPre FileChangedRO FileChangedShell FileEncoding FileReadCmd FileReadPost FileReadPre FileType FileWriteCmd FileWritePost FileWritePre FilterReadPost FilterReadPre FilterWritePost FilterWritePre FocusGained FocusLost FuncUndefined GUIEnter InsertChange InsertEnter InsertLeave RemoteReply StdinReadPost StdinReadPre Syntax TermChanged TermResponse User UserGettingBored VimEnter VimLeave VimLeavePre WinEnter WinLeave +syn keyword vimAutoEvent contained BufAdd BufCreate BufDelete BufEnter BufFilePost BufFilePre BufHidden BufLeave BufNew BufNewFile BufRead BufReadCmd BufReadPost BufReadPre BufUnload BufWinEnter BufWinLeave BufWipeout BufWrite BufWriteCmd BufWritePost BufWritePre Cmd-event CmdwinEnter CmdwinLeave ColorScheme CursorHold E135 E143 E200 E201 E203 E204 EncodingChanged FileAppendCmd FileAppendPost FileAppendPre FileChangedRO FileChangedShell FileEncoding FileReadCmd FileReadPost FileReadPre FileType FileWriteCmd FileWritePost FileWritePre FilterReadPost FilterReadPre FilterWritePost FilterWritePre FocusGained FocusLost FuncUndefined GUIEnter InsertChange InsertEnter InsertLeave QuickFixCmdPre QuickFixCmdPost RemoteReply StdinReadPost StdinReadPre Syntax TermChanged TermResponse User UserGettingBored VimEnter VimLeave VimLeavePre WinEnter WinLeave " Highlight commonly used Groupnames {{{2 syn keyword vimGroup contained Comment Constant String Character Number Boolean Float Identifier Function Statement Conditional Repeat Label Operator Keyword Exception PreProc Include Define Macro PreCondit Type StorageClass Structure Typedef Special SpecialChar Tag Delimiter SpecialComment Debug Underlined Ignore Error Todo diff --git a/src/edit.c b/src/edit.c index 175256e64..a8897362d 100644 --- a/src/edit.c +++ b/src/edit.c @@ -5151,7 +5151,9 @@ cursor_up(n, upd_topline) if (n > 0) { lnum = curwin->w_cursor.lnum; - if (lnum <= 1) + /* This fails if the cursor is already in the first line or the count + * is larger than the line number and '-' is in 'cpoptions' */ + if (lnum <= 1 || (n >= lnum && vim_strchr(p_cpo, CPO_MINUS) != NULL)) return FAIL; if (n >= lnum) lnum = 1; @@ -5212,7 +5214,11 @@ cursor_down(n, upd_topline) /* Move to last line of fold, will fail if it's the end-of-file. */ (void)hasFolding(lnum, NULL, &lnum); #endif - if (lnum >= curbuf->b_ml.ml_line_count) + /* This fails if the cursor is already in the last line or would move + * beyound the last line and '-' is in 'cpoptions' */ + if (lnum >= curbuf->b_ml.ml_line_count + || (lnum + n > curbuf->b_ml.ml_line_count + && vim_strchr(p_cpo, CPO_MINUS) != NULL)) return FAIL; if (lnum + n >= curbuf->b_ml.ml_line_count) lnum = curbuf->b_ml.ml_line_count; diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c index 82557febb..6c8ece95b 100644 --- a/src/ex_cmds2.c +++ b/src/ex_cmds2.c @@ -2339,11 +2339,12 @@ do_source(fname, check_other, is_vimrc) if (SCRIPT_NAME(current_SID) != NULL && ( # ifdef UNIX - /* compare dev/ino when possible, it catches symbolic - * links */ - (stat_ok && SCRIPT_DEV(current_SID) != -1) - ? (SCRIPT_DEV(current_SID) == st.st_dev - && SCRIPT_INO(current_SID) == st.st_ino) : + /* Compare dev/ino when possible, it catches symbolic + * links. Also compare file names, the inode may change + * when the file was edited. */ + ((stat_ok && SCRIPT_DEV(current_SID) != -1) + && (SCRIPT_DEV(current_SID) == st.st_dev + && SCRIPT_INO(current_SID) == st.st_ino)) || # endif fnamecmp(SCRIPT_NAME(current_SID), fname_exp) == 0)) break; diff --git a/src/ex_docmd.c b/src/ex_docmd.c index 5cecf30c6..899e4c8f4 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -594,6 +594,14 @@ do_exmode(improved) MSG(_("Entering Ex mode. Type \"visual\" to go to Normal mode.")); while (exmode_active) { +#ifdef FEAT_EX_EXTRA + /* Check for a ":normal" command and no more characters left. */ + if (ex_normal_busy > 0 && typebuf.tb_len == 0) + { + exmode_active = FALSE; + break; + } +#endif msg_scroll = TRUE; need_wait_return = FALSE; ex_pressedreturn = FALSE; diff --git a/src/ex_getln.c b/src/ex_getln.c index e17e671ef..a7dfd9a75 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -996,8 +996,13 @@ getcmdline(firstc, count, indent) case ESC: /* get here if p_wc != ESC or when ESC typed twice */ case Ctrl_C: - /* In exmode it doesn't make sense to return. */ - if (exmode_active) + /* In exmode it doesn't make sense to return. Except when + * ":normal" runs out of characters. */ + if (exmode_active +#ifdef FEAT_EX_EXTRA + && (ex_normal_busy == 0 || typebuf.tb_len > 0) +#endif + ) goto cmdline_not_changed; gotesc = TRUE; /* will free ccline.cmdbuff after diff --git a/src/fileio.c b/src/fileio.c index ee1c90b88..ea7c924d9 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -2701,6 +2701,7 @@ buf_write(buf, fname, sfname, start, end, eap, append, forceit, int buf_fname_s = FALSE; int did_cmd = FALSE; int nofile_err = FALSE; + int empty_memline = (buf->b_ml.ml_mfp == NULL); /* * Apply PRE aucocommands. @@ -2772,7 +2773,7 @@ buf_write(buf, fname, sfname, start, end, eap, append, forceit, */ if (!buf_valid(buf)) buf = NULL; - if (buf == NULL || buf->b_ml.ml_mfp == NULL + if (buf == NULL || (buf->b_ml.ml_mfp == NULL && !empty_memline) || did_cmd || nofile_err || aborting()) { --no_wait_return; @@ -6650,6 +6651,8 @@ static struct event_name {"InsertChange", EVENT_INSERTCHANGE}, {"InsertEnter", EVENT_INSERTENTER}, {"InsertLeave", EVENT_INSERTLEAVE}, + {"QuickFixCmdPost", EVENT_QUICKFIXCMDPOST}, + {"QuickFixCmdPre", EVENT_QUICKFIXCMDPRE}, {"RemoteReply", EVENT_REMOTEREPLY}, {"StdinReadPost", EVENT_STDINREADPOST}, {"StdinReadPre", EVENT_STDINREADPRE}, @@ -8042,9 +8045,12 @@ apply_autocmds_group(event, fname, fname_io, force, group, buf, eap) else { sfname = vim_strsave(fname); - /* Don't try expanding FileType, Syntax or WindowID. */ - if (event == EVENT_FILETYPE || event == EVENT_SYNTAX - || event == EVENT_REMOTEREPLY) + /* Don't try expanding FileType, Syntax, WindowID or QuickFixCmd* */ + if (event == EVENT_FILETYPE + || event == EVENT_SYNTAX + || event == EVENT_REMOTEREPLY + || event == EVENT_QUICKFIXCMDPRE + || event == EVENT_QUICKFIXCMDPOST) fname = vim_strsave(fname); else fname = FullName_save(fname, FALSE); diff --git a/src/gui_motif.c b/src/gui_motif.c index acb9d81fa..a1da3d0af 100644 --- a/src/gui_motif.c +++ b/src/gui_motif.c @@ -886,7 +886,8 @@ gui_mch_compute_menu_height(id) #include "gui_x11_pm.h" static int check_xpm __ARGS((char_u *path)); -static char **get_toolbar_pixmap __ARGS((vimmenu_T *menu)); +static char **get_toolbar_pixmap __ARGS((vimmenu_T *menu, char **fname)); +static int add_pixmap_args __ARGS((vimmenu_T *menu, Arg *args, int n)); /* * Read an Xpm file. Return OK or FAIL. @@ -916,16 +917,20 @@ check_xpm(path) /* * Allocated a pixmap for toolbar menu "menu". + * When it's to be read from a file, "fname" is set to the file name + * (in allocated memory). * Return a blank pixmap if it fails. */ static char ** -get_toolbar_pixmap(menu) +get_toolbar_pixmap(menu, fname) vimmenu_T *menu; + char **fname; { char_u buf[MAXPATHL]; /* buffer storing expanded pathname */ char **xpm = NULL; /* xpm array */ int res; + *fname = NULL; buf[0] = NUL; /* start with NULL path */ if (menu->iconfile != NULL) @@ -938,7 +943,10 @@ get_toolbar_pixmap(menu) if (res == FAIL && gui_find_bitmap(menu->name, buf, "xpm") == OK) res = check_xpm(buf); if (res == OK) + { + *fname = (char *)vim_strsave(buf); return tb_blank_xpm; + } } if (menu->icon_builtin || gui_find_bitmap(menu->name, buf, "xpm") == FAIL) @@ -952,6 +960,33 @@ get_toolbar_pixmap(menu) return xpm; } + +/* + * Add arguments for the toolbar pixmap to a menu item. + */ + static int +add_pixmap_args(menu, args, n) + vimmenu_T *menu; + Arg *args; + int n; +{ + vim_free(menu->xpm_fname); + menu->xpm = get_toolbar_pixmap(menu, &menu->xpm_fname); + if (menu->xpm == NULL) + { + XtSetArg(args[n], XmNlabelType, XmSTRING); n++; + } + else + { + if (menu->xpm_fname != NULL) + { + XtSetArg(args[n], XmNpixmapFile, menu->xpm_fname); n++; + } + XtSetArg(args[n], XmNpixmapData, menu->xpm); n++; + XtSetArg(args[n], XmNlabelLocation, XmBOTTOM); n++; + } + return n; +} #endif /* FEAT_TOOLBAR */ void @@ -1025,16 +1060,8 @@ gui_mch_add_menu_item(menu, idx) xms = XmStringCreate((char *)menu->dname, STRING_TAG); XtSetArg(args[n], XmNlabelString, xms); n++; - menu->xpm = get_toolbar_pixmap(menu); - if (menu->xpm == NULL) - { - XtSetArg(args[n], XmNlabelType, XmSTRING); n++; - } - else - { - XtSetArg(args[n], XmNpixmapData, menu->xpm); n++; - XtSetArg(args[n], XmNlabelLocation, XmBOTTOM); n++; - } + n = add_pixmap_args(menu, args, n); + type = xmEnhancedButtonWidgetClass; } @@ -1264,16 +1291,7 @@ submenu_change(menu, colors) int n = 0; Arg args[18]; - mp->xpm = get_toolbar_pixmap(mp); - if (menu->xpm == NULL) - { - XtSetArg(args[n], XmNlabelType, XmSTRING); n++; - } - else - { - XtSetArg(args[n], XmNpixmapData, menu->xpm); n++; - XtSetArg(args[n], XmNlabelLocation, XmBOTTOM); n++; - } + n = add_pixmap_args(mp, args, n); XtSetValues(mp->id, args, n); } # ifdef FEAT_BEVAL @@ -2846,6 +2864,23 @@ gui_mch_compute_toolbar_height() return (int)(height + (borders << 1)); } + void +motif_get_toolbar_colors(bgp, fgp, bsp, tsp, hsp) + Pixel *bgp; + Pixel *fgp; + Pixel *bsp; + Pixel *tsp; + Pixel *hsp; +{ + XtVaGetValues(toolBar, + XmNbackground, bgp, + XmNforeground, fgp, + XmNbottomShadowColor, bsp, + XmNtopShadowColor, tsp, + XmNhighlightColor, hsp, + NULL); +} + # ifdef FEAT_FOOTER /* * The next toolbar enter/leave callbacks should really do balloon help. But diff --git a/src/gui_xmebw.c b/src/gui_xmebw.c index aa22a88b1..ff7d2e68d 100644 --- a/src/gui_xmebw.c +++ b/src/gui_xmebw.c @@ -292,13 +292,14 @@ set_pixmap(XmEnhancedButtonWidget eb) int x; int y; unsigned int height, width, border, depth; - int status; + int status = 0; Pixmap mask; Pixmap pix = None; Pixmap arm_pix = None; Pixmap ins_pix = None; Pixmap high_pix = None; char **data = (char **) eb->enhancedbutton.pixmap_data; + char *fname = (char *) eb->enhancedbutton.pixmap_file; int shift; GC gc; @@ -313,6 +314,7 @@ set_pixmap(XmEnhancedButtonWidget eb) root = RootWindow(dpy, scr); eb->label.pixmap = None; + eb->enhancedbutton.pixmap_depth = 0; eb->enhancedbutton.pixmap_width = 0; eb->enhancedbutton.pixmap_height = 0; @@ -321,6 +323,14 @@ set_pixmap(XmEnhancedButtonWidget eb) eb->enhancedbutton.highlight_pixmap = None; eb->enhancedbutton.insensitive_pixmap = None; + /* We use dynamic colors, get them now. */ + motif_get_toolbar_colors( + &eb->core.background_pixel, + &eb->primitive.foreground, + &eb->primitive.bottom_shadow_color, + &eb->primitive.top_shadow_color, + &eb->primitive.highlight_color); + /* Setup color subsititution table. */ color[0].pixel = eb->core.background_pixel; color[1].pixel = eb->core.background_pixel; @@ -337,9 +347,12 @@ set_pixmap(XmEnhancedButtonWidget eb) attr.colorsymbols = color; attr.numsymbols = XtNumber(color); - status = XpmCreatePixmapFromData(dpy, root, data, &pix, &mask, &attr); + if (fname) + status = XpmReadFileToPixmap(dpy, root, fname, &pix, &mask, &attr); + if (!fname || status != XpmSuccess) + status = XpmCreatePixmapFromData(dpy, root, data, &pix, &mask, &attr); - /* If somethin failed, we will fill in the default pixmap. */ + /* If something failed, we will fill in the default pixmap. */ if (status != XpmSuccess) status = XpmCreatePixmapFromData(dpy, root, blank_xpm, &pix, &mask, &attr); diff --git a/src/move.c b/src/move.c index 2fc226056..f3d7825f3 100644 --- a/src/move.c +++ b/src/move.c @@ -2471,7 +2471,8 @@ onepage(dir, count) foldAdjustCursor(); #endif cursor_correct(); - beginline(BL_SOL | BL_FIX); + if (retval == OK) + beginline(BL_SOL | BL_FIX); curwin->w_valid &= ~(VALID_WCOL|VALID_WROW|VALID_VIRTCOL); /* @@ -5829,16 +5829,16 @@ clear_oparg(oap) vim_memset(oap, 0, sizeof(oparg_T)); } -static long line_count_info __ARGS((char_u *line, long *wc, long limit, int eol_size)); +static long line_count_info __ARGS((char_u *line, long *wc, long *cc, long limit, int eol_size)); /* - * Count the number of characters and "words" in a line. + * Count the number of bytes, characters and "words" in a line. * * "Words" are counted by looking for boundaries between non-space and * space characters. (it seems to produce results that match 'wc'.) * - * Return value is character count; word count for the line is ADDED - * to "*wc". + * Return value is byte count; word count for the line is added to "*wc". + * Char count is added to "*cc". * * The function will only examine the first "limit" characters in the * line, stopping if it encounters an end-of-line (NUL byte). In that @@ -5846,16 +5846,19 @@ static long line_count_info __ARGS((char_u *line, long *wc, long limit, int eol_ * the size of the EOL character. */ static long -line_count_info(line, wc, limit, eol_size) +line_count_info(line, wc, cc, limit, eol_size) char_u *line; long *wc; + long *cc; long limit; int eol_size; { - long i, words = 0; + long i; + long words = 0; + long chars = 0; int is_word = 0; - for (i = 0; line[i] && i < limit; i++) + for (i = 0; line[i] && i < limit; ) { if (is_word) { @@ -5867,6 +5870,12 @@ line_count_info(line, wc, limit, eol_size) } else if (!vim_isspace(line[i])) is_word = 1; + ++chars; +#ifdef FEAT_MBYTE + i += mb_ptr2len_check(line + i); +#else + ++i; +#endif } if (is_word) @@ -5874,8 +5883,12 @@ line_count_info(line, wc, limit, eol_size) *wc += words; /* Add eol_size if the end of line was reached before hitting limit. */ - if (!line[i] && i < limit) + if (line[i] == NUL && i < limit) + { i += eol_size; + chars += eol_size; + } + *cc += chars; return i; } @@ -5891,12 +5904,14 @@ cursor_pos_info() char_u buf1[20]; char_u buf2[20]; linenr_T lnum; + long byte_count = 0; + long byte_count_cursor = 0; long char_count = 0; long char_count_cursor = 0; - int eol_size; - long last_check = 100000L; long word_count = 0; long word_count_cursor = 0; + int eol_size; + long last_check = 100000L; #ifdef FEAT_VISUAL long line_count_selected = 0; pos_T min_pos, max_pos; @@ -5956,12 +5971,12 @@ cursor_pos_info() for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) { /* Check for a CTRL-C every 100000 characters. */ - if (char_count > last_check) + if (byte_count > last_check) { ui_breakcheck(); if (got_int) return; - last_check = char_count + 100000L; + last_check = byte_count + 100000L; } #ifdef FEAT_VISUAL @@ -6003,13 +6018,13 @@ cursor_pos_info() } if (s != NULL) { - char_count_cursor += line_count_info(s, - &word_count_cursor, len, eol_size); + byte_count_cursor += line_count_info(s, &word_count_cursor, + &char_count_cursor, len, eol_size); if (lnum == curbuf->b_ml.ml_line_count && !curbuf->b_p_eol && curbuf->b_p_bin && (long)STRLEN(s) < len) - char_count_cursor -= eol_size; + byte_count_cursor -= eol_size; } } else @@ -6019,19 +6034,21 @@ cursor_pos_info() if (lnum == curwin->w_cursor.lnum) { word_count_cursor += word_count; - char_count_cursor = char_count + - line_count_info(ml_get(lnum), &word_count_cursor, + char_count_cursor += char_count; + byte_count_cursor = byte_count + + line_count_info(ml_get(lnum), + &word_count_cursor, &char_count_cursor, (long)(curwin->w_cursor.col + 1), eol_size); } } /* Add to the running totals */ - char_count += line_count_info(ml_get(lnum), &word_count, - (long)MAXCOL, eol_size); + byte_count += line_count_info(ml_get(lnum), &word_count, + &char_count, (long)MAXCOL, eol_size); } /* Correction for when last line doesn't have an EOL. */ if (!curbuf->b_p_eol && curbuf->b_p_bin) - char_count -= eol_size; + byte_count -= eol_size; #ifdef FEAT_VISUAL if (VIsual_active) @@ -6046,12 +6063,20 @@ cursor_pos_info() else buf1[0] = NUL; - sprintf((char *)IObuff, - _("Selected %s%ld of %ld Lines; %ld of %ld Words; %ld of %ld Bytes"), + if (char_count_cursor == byte_count_cursor + && char_count == byte_count) + sprintf((char *)IObuff, _("Selected %s%ld of %ld Lines; %ld of %ld Words; %ld of %ld Bytes"), buf1, line_count_selected, (long)curbuf->b_ml.ml_line_count, word_count_cursor, word_count, - char_count_cursor, char_count); + byte_count_cursor, byte_count); + else + sprintf((char *)IObuff, _("Selected %s%ld of %ld Lines; %ld of %ld Words; %ld of %ld Chars; %ld of %ld Bytes"), + buf1, line_count_selected, + (long)curbuf->b_ml.ml_line_count, + word_count_cursor, word_count, + char_count_cursor, char_count, + byte_count_cursor, byte_count); } else #endif @@ -6062,20 +6087,29 @@ cursor_pos_info() (int)curwin->w_virtcol + 1); col_print(buf2, (int)STRLEN(p), linetabsize(p)); - sprintf((char *)IObuff, - _("Col %s of %s; Line %ld of %ld; Word %ld of %ld; Byte %ld of %ld"), + if (char_count_cursor == byte_count_cursor + && char_count == byte_count) + sprintf((char *)IObuff, _("Col %s of %s; Line %ld of %ld; Word %ld of %ld; Byte %ld of %ld"), + (char *)buf1, (char *)buf2, + (long)curwin->w_cursor.lnum, + (long)curbuf->b_ml.ml_line_count, + word_count_cursor, word_count, + byte_count_cursor, byte_count); + else + sprintf((char *)IObuff, _("Col %s of %s; Line %ld of %ld; Word %ld of %ld; Char %ld of %ld; Byte %ld of %ld"), (char *)buf1, (char *)buf2, (long)curwin->w_cursor.lnum, (long)curbuf->b_ml.ml_line_count, word_count_cursor, word_count, - char_count_cursor, char_count); + char_count_cursor, char_count, + byte_count_cursor, byte_count); } #ifdef FEAT_MBYTE - char_count = bomb_size(); - if (char_count > 0) + byte_count = bomb_size(); + if (byte_count > 0) sprintf((char *)IObuff + STRLEN(IObuff), _("(+%ld for BOM)"), - char_count); + byte_count); #endif /* Don't shorten this message, the user asked for it. */ p = p_shm; diff --git a/src/option.c b/src/option.c index 0c6178d63..ffeaf8644 100644 --- a/src/option.c +++ b/src/option.c @@ -2593,18 +2593,19 @@ set_init_1() /* * Find default value for 'shell' option. + * Don't use it if it is empty. */ - if ((p = mch_getenv((char_u *)"SHELL")) != NULL + if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL) #if defined(MSDOS) || defined(MSWIN) || defined(OS2) # ifdef __EMX__ - || (p = mch_getenv((char_u *)"EMXSHELL")) != NULL + || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL) # endif - || (p = mch_getenv((char_u *)"COMSPEC")) != NULL + || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL) # ifdef WIN3264 - || (p = default_shell()) != NULL + || ((p = default_shell()) != NULL && *p != NUL) # endif #endif - ) + ) set_string_default("sh", p); #ifdef FEAT_WILDIGN diff --git a/src/option.h b/src/option.h index 1fb5488d3..9be2c4988 100644 --- a/src/option.h +++ b/src/option.h @@ -162,9 +162,10 @@ #define CPO_MATCH '%' #define CPO_STAR '*' /* ":*" means ":@" */ #define CPO_PLUS '+' /* ":write file" resets 'modified' */ +#define CPO_MINUS '-' /* "9-" fails at and before line 9 */ #define CPO_SPECI '<' /* don't recognize <> in mappings */ #define CPO_DEFAULT "aABceFs" -#define CPO_ALL "aAbBcCdDeEfFgiIjJkKlLmMnoOprRsStuvwWxy$!%*+<" +#define CPO_ALL "aAbBcCdDeEfFgiIjJkKlLmMnoOprRsStuvwWxy$!%*-+<" /* characters for p_ww option: */ #define WW_ALL "bshl<>[],~" diff --git a/src/os_unix.c b/src/os_unix.c index 4dd38ce7e..c09638f4c 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -3222,8 +3222,9 @@ mch_get_shellsize() /* * 2. get size from environment + * When being POSIX compliant this overrules the ioctl() values! */ - if (columns == 0 || rows == 0) + if (columns == 0 || rows == 0 || getenv("VIM_POSIX") != NULL) { if ((p = (char_u *)getenv("LINES"))) rows = atoi((char *)p); diff --git a/src/proto/gui_motif.pro b/src/proto/gui_motif.pro index 94a7c4519..8c49d2f2f 100644 --- a/src/proto/gui_motif.pro +++ b/src/proto/gui_motif.pro @@ -34,6 +34,7 @@ void gui_mch_enable_footer __ARGS((int showit)); void gui_mch_set_footer __ARGS((char_u *s)); void gui_mch_show_toolbar __ARGS((int showit)); int gui_mch_compute_toolbar_height __ARGS((void)); +void motif_get_toolbar_colors __ARGS((Pixel *bgp, Pixel *fgp, Pixel *bsp, Pixel *tsp, Pixel *hsp)); void gui_motif_menu_fontlist __ARGS((Widget id)); void gui_mch_find_dialog __ARGS((exarg_T *eap)); void gui_mch_replace_dialog __ARGS((exarg_T *eap)); diff --git a/src/quickfix.c b/src/quickfix.c index a4110035f..a8544b34e 100644 --- a/src/quickfix.c +++ b/src/quickfix.c @@ -2083,9 +2083,27 @@ grep_internal(cmdidx) ex_make(eap) exarg_T *eap; { - char_u *name; + char_u *fname; char_u *cmd; unsigned len; +#ifdef FEAT_AUTOCMD + char_u *au_name = NULL; + + switch (eap->cmdidx) + { + case CMD_make: au_name = (char_u *)"make"; break; + case CMD_grep: au_name = (char_u *)"grep"; break; + case CMD_grepadd: au_name = (char_u *)"grepadd"; break; + default: break; + } + if (au_name != NULL) + { + apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, + curbuf->b_fname, TRUE, curbuf); + if (did_throw || force_abort) + return; + } +#endif /* Redirect ":grep" to ":vimgrep" if 'grepprg' is "internal". */ if (grep_internal(eap->cmdidx)) @@ -2095,24 +2113,24 @@ ex_make(eap) } autowrite_all(); - name = get_mef_name(); - if (name == NULL) + fname = get_mef_name(); + if (fname == NULL) return; - mch_remove(name); /* in case it's not unique */ + mch_remove(fname); /* in case it's not unique */ /* * If 'shellpipe' empty: don't redirect to 'errorfile'. */ len = (unsigned)STRLEN(p_shq) * 2 + (unsigned)STRLEN(eap->arg) + 1; if (*p_sp != NUL) - len += (unsigned)STRLEN(p_sp) + (unsigned)STRLEN(name) + 3; + len += (unsigned)STRLEN(p_sp) + (unsigned)STRLEN(fname) + 3; cmd = alloc(len); if (cmd == NULL) return; sprintf((char *)cmd, "%s%s%s", (char *)p_shq, (char *)eap->arg, (char *)p_shq); if (*p_sp != NUL) - append_redir(cmd, p_sp, name); + append_redir(cmd, p_sp, fname); /* * Output a newline if there's something else than the :make command that * was typed (in which case the cursor is in column 0). @@ -2132,14 +2150,20 @@ ex_make(eap) (void)char_avail(); #endif - if (qf_init(name, eap->cmdidx != CMD_make ? p_gefm : p_efm, + if (qf_init(fname, eap->cmdidx != CMD_make ? p_gefm : p_efm, eap->cmdidx != CMD_grepadd) > 0 && !eap->forceit) qf_jump(0, 0, FALSE); /* display first error */ - mch_remove(name); - vim_free(name); + mch_remove(fname); + vim_free(fname); vim_free(cmd); + +#ifdef FEAT_AUTOCMD + if (au_name != NULL) + apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, + curbuf->b_fname, TRUE, curbuf); +#endif } /* @@ -2275,6 +2299,23 @@ ex_vimgrep(eap) char_u *save_ei = NULL; aco_save_T aco; #endif +#ifdef FEAT_AUTOCMD + char_u *au_name = NULL; + + switch (eap->cmdidx) + { + case CMD_vimgrep: au_name = (char_u *)"vimgrep"; break; + case CMD_vimgrepadd: au_name = (char_u *)"vimgrepadd"; break; + default: break; + } + if (au_name != NULL) + { + apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, + curbuf->b_fname, TRUE, curbuf); + if (did_throw || force_abort) + return; + } +#endif /* Make 'cpoptions' empty, the 'l' flag should not be used here. */ save_cpo = p_cpo; @@ -2496,6 +2537,12 @@ jumpend: else EMSG2(_(e_nomatch2), s); +#ifdef FEAT_AUTOCMD + if (au_name != NULL) + apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, + curbuf->b_fname, TRUE, curbuf); +#endif + theend: vim_free(regmatch.regprog); diff --git a/src/structs.h b/src/structs.h index ff4d2d64e..8a81611c2 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1967,6 +1967,7 @@ struct VimMenu #ifdef FEAT_GUI_MOTIF int sensitive; /* turn button on/off */ char **xpm; /* pixmap data */ + char *xpm_fname; /* file with pixmap data */ #endif #ifdef FEAT_GUI_ATHENA Pixmap image; /* Toolbar image */ diff --git a/src/version.h b/src/version.h index 187babb41..6dfc7d5fc 100644 --- a/src/version.h +++ b/src/version.h @@ -36,5 +36,5 @@ #define VIM_VERSION_NODOT "vim70aa" #define VIM_VERSION_SHORT "7.0aa" #define VIM_VERSION_MEDIUM "7.0aa ALPHA" -#define VIM_VERSION_LONG "VIM - Vi IMproved 7.0aa ALPHA (2005 Feb 5)" -#define VIM_VERSION_LONG_DATE "VIM - Vi IMproved 7.0aa ALPHA (2005 Feb 5, compiled " +#define VIM_VERSION_LONG "VIM - Vi IMproved 7.0aa ALPHA (2005 Feb 7)" +#define VIM_VERSION_LONG_DATE "VIM - Vi IMproved 7.0aa ALPHA (2005 Feb 7, compiled " @@ -1074,6 +1074,8 @@ enum auto_event EVENT_INSERTCHANGE, /* when changing Insert/Replace mode */ EVENT_INSERTENTER, /* when entering Insert mode */ EVENT_INSERTLEAVE, /* when leaving Insert mode */ + EVENT_QUICKFIXCMDPOST, /* after :make, :grep etc */ + EVENT_QUICKFIXCMDPRE, /* before :make, :grep etc */ EVENT_STDINREADPOST, /* after reading from stdin */ EVENT_STDINREADPRE, /* before reading from stdin */ EVENT_SYNTAX, /* syntax selected */ |