aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-06-08 00:44:19 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-06-08 00:44:19 +0200
commitdb5957a696dc83eda3f3b53685c3586618499a1c (patch)
treeaaa62fa6c80cfead21307a6cfcac0856b25883b3
parent10c638d1824950d80df52a691b562d772d6e25e2 (diff)
downloaddwim-db5957a696dc83eda3f3b53685c3586618499a1c.tar.gz
Handle function(call
-rwxr-xr-xdwim31
1 files changed, 22 insertions, 9 deletions
diff --git a/dwim b/dwim
index a9b56df..74d6c62 100755
--- a/dwim
+++ b/dwim
@@ -5,7 +5,7 @@
use v5.24;
use warnings;
use strict;
-use subs qw/path env handle fail run arguments/;
+use subs qw/arguments dir env fail handle path run/;
my ($DEBUG, $handler, $phrase);
@@ -62,18 +62,27 @@ for ($phrase) {
# otherwise fall through
}
- if (/^(\S+)\((\d+)\)[):,.]*$/) {
+ if (/^([-_A-Za-z]+)\((\d+)\)[):,.]*$/) {
handle 'manual(section)';
run @MAN_VIEWER, $2, $1;
}
- if (/^([A-Za-z]+)\.([1-9])$/) {
+ if (/^([-_A-Za-z]+)\.([1-9])$/) {
handle 'manual.section';
my $p = path "$1.$2";
run @MAN_VIEWER, $p if -e $p;
run @MAN_VIEWER, $2, $1;
}
+ if (/^([A-Za-z_][A-Za-z0-9_]*)\(/) {
+ handle 'function(call';
+ my $dir = dir;
+ s/\(.*//;
+ for (`grep -n '^$_' "$dir"/*.c "$dir"/*.h`) {
+ run @EDITOR, "+$2", $1 if /([^:]+):(\d+):/;
+ }
+ }
+
if (/^<(\S+)>$/) {
handle '<header.h>';
open my $h, 'find / -maxdepth 3 -type d -name include 2>&-|'
@@ -104,11 +113,7 @@ for ($phrase) {
die "no handler matched by: $phrase\n"
}
-sub path {
- my $n = shift;
- $n =~ s,^~([^/]+),/home/$1,;
- $n =~ s,^~,/home/$ENV{USER},;
- return $n if $n =~ /^\// or $n =~ /^~/;
+sub dir {
for (`xtitle`) {
chomp;
s/.*\(([^(]+)\)$/$1/;
@@ -116,11 +121,19 @@ sub path {
s,^~,/home/$ENV{USER},;
die "couldn't retrieve current directory\n"
if ! -d $_ and ! -d ($_ = dirname($_));
- return "$_/$n";
+ return $_;
}
die "couldn't retrieve current directory: xtitle not installed\n";
}
+sub path {
+ my $n = shift;
+ $n =~ s,^~([^/]+),/home/$1,;
+ $n =~ s,^~,/home/$ENV{USER},;
+ return $n if $n =~ /^\// or $n =~ /^~/;
+ return dir . "/$n";
+}
+
# take K => V and return environment variable K if defined, otherwise V
sub env {
my %h = @_;