From db5957a696dc83eda3f3b53685c3586618499a1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 8 Jun 2021 00:44:19 +0200 Subject: Handle function(call --- dwim | 31 ++++++++++++++++++++++--------- 1 file 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 ''; 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 = @_; -- cgit v1.2.3