diff options
author | John Ankarström <john@ankarstrom.se> | 2021-06-08 00:44:19 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-06-08 00:44:19 +0200 |
commit | db5957a696dc83eda3f3b53685c3586618499a1c (patch) | |
tree | aaa62fa6c80cfead21307a6cfcac0856b25883b3 | |
parent | 10c638d1824950d80df52a691b562d772d6e25e2 (diff) | |
download | dwim-db5957a696dc83eda3f3b53685c3586618499a1c.tar.gz |
Handle function(call
-rwxr-xr-x | dwim | 31 |
1 files changed, 22 insertions, 9 deletions
@@ -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 = @_; |