Skip to content

Commit

Permalink
implement gq (format through formatprg) and enable the menu item
Browse files Browse the repository at this point in the history
adds a 'formatprg' setting
  • Loading branch information
martinh committed Jul 8, 2012
1 parent aed2fbc commit 76d16b3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
25 changes: 25 additions & 0 deletions Credits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,28 @@ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.


================================================================================
Vico include the par paragraph formatter by Adam M. Costello.
Par is available from http://www.nicemice.net/par/.
The par version shipped with Vico includes the par_1.52-i18n.3.diff.gz patch
by Jérôme Pouiller that adds multibyte support.

The files listed in the Files List section above are each Copyright
2001 by Adam M. Costello (henceforth "I", "me").

I grant everyone ("you") permission to do whatever you like with
these files, provided that if you modify them you take reasonable
steps to avoid confusing or misleading people about who wrote the
modified files (both you and I) or what version they are. All
official versions of Par will have version numbers consisting of
only digits and periods.

I encourage you to send me copies of your modifications in case I
wish to incorporate them into future versions of Par. See the Bugs
section for my address.

Though I have tried to make sure that Par is free of bugs, I make no
guarantees about its soundness. Therefore, I am not responsible for
any damage resulting from the use of these files.

1 change: 1 addition & 0 deletions app/ExEnvironment.m
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ - (void)ex_set:(ExCommand *)command
@"antialias", @"antialias",
@"undostyle", @"undostyle",
@"list", @"list",
@"formatprg", @"fp",
nil];

NSArray *booleans = [NSArray arrayWithObjects:
Expand Down
11 changes: 11 additions & 0 deletions app/ViTextView-vi_commands.m
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ - (void)filterFinishedWithStatus:(int)status standardOutput:(NSString *)outputTe
NSRange range = [(NSValue *)contextInfo rangeValue];
[self replaceRange:range withString:outputText];
[self endUndoGroup];
final_location = range.location + [outputText length];
[self setCaret:final_location];
} else
MESSAGE(@"filter exited with status %i", status);
}
Expand Down Expand Up @@ -373,6 +375,15 @@ - (BOOL)filter:(ViCommand *)command
return YES;
}

- (BOOL)format:(ViCommand *)command
{
NSString *formatprg = [[NSUserDefaults standardUserDefaults] stringForKey:@"formatprg"];
if ([formatprg length] == 0)
formatprg = @"par";
[self filter_through_shell_command:formatprg contextInfo:command];
return YES;
}

/* syntax: [count]} */
- (BOOL)paragraph_forward:(ViCommand *)command
{
Expand Down
1 change: 0 additions & 1 deletion app/en.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,6 @@
</object>
<object class="NSMenuItem" id="704246332">
<reference key="NSMenu" ref="789758025"/>
<bool key="NSIsDisabled">YES</bool>
<string key="NSTitle">Reformat Paragraph / Selection (gqap)(gq)</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
Expand Down
5 changes: 3 additions & 2 deletions app/keys.nu
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,13 @@
(nmap include:wmap)
;; g prefix
(nmap setKey:"gU" toOperator:"uppercase:")
(nmap setKey:"gUU" toEditAction:"uppercase:" flags:ViMapLineMode parameter:nil scope:nil)
(nmap setKey:"gUgU" toEditAction:"uppercase:" flags:ViMapLineMode parameter:nil scope:nil)
(nmap setKey:"gu" toOperator:"lowercase:")
(nmap setKey:"guu" toEditAction:"lowercase:" flags:ViMapLineMode parameter:nil scope:nil)
(nmap setKey:"gugu" toEditAction:"lowercase:" flags:ViMapLineMode parameter:nil scope:nil)
(nmap setKey:"gt" toAction:"next_tab:")
(nmap setKey:"gT" toAction:"previous_tab:")
(nmap setKey:"gq" toOperator:"format:")
(nmap setKey:"gqgq" toEditAction:"format:" flags:ViMapLineMode parameter:nil scope:nil)


;; operator map
Expand Down Expand Up @@ -275,6 +275,7 @@
(vmap setKey:"gu" toEditAction:"lowercase:")
(vmap setKey:"gt" toAction:"next_tab:")
(vmap setKey:"gT" toAction:"previous_tab:")
(vmap setKey:"gq" toEditAction:"format:")
(vmap setKey:"p" toEditAction:"put_after:")
(vmap setKey:"r" toEditAction:"replace:" flags:ViMapNeedArgument parameter:nil scope:nil)
(vmap setKey:"s" toEditAction:"substitute:")
Expand Down

0 comments on commit 76d16b3

Please sign in to comment.