From 5aa548cd63edb8ba12c656300a2a5f0ff62a7b36 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Thu, 8 Nov 2012 18:59:30 +0100 Subject: support globbing in EB...$ to support opening multiple files at once --- qbuffers.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 6 deletions(-) (limited to 'qbuffers.cpp') diff --git a/qbuffers.cpp b/qbuffers.cpp index 03f9562..5f33417 100644 --- a/qbuffers.cpp +++ b/qbuffers.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -124,21 +125,67 @@ Ring::~Ring() delete buffer; } +/* + * Auxiliary functions + */ +static inline bool +is_glob_pattern(const gchar *str) +{ + return strchr(str, '*') || strchr(str, '?'); +} + /* * Command states */ +void +StateFile::do_edit(const gchar *filename) +{ + ring.undo_edit(); + if (ring.edit(filename)) + ring.undo_close(); +} + State * StateFile::done(const gchar *str) { - bool new_in_ring; - BEGIN_EXEC(&states.start); - ring.undo_edit(); - new_in_ring = ring.edit(*str ? str : NULL); - if (new_in_ring) - ring.undo_close(); + if (is_glob_pattern(str)) { + gchar *dirname; + GDir *dir; + + dirname = g_path_get_dirname(str); + dir = g_dir_open(dirname, 0, NULL); + + if (dir) { + const gchar *basename; + GPatternSpec *pattern; + + basename = g_path_get_basename(str); + pattern = g_pattern_spec_new(basename); + g_free((gchar *)basename); + + while ((basename = g_dir_read_name(dir))) { + if (g_pattern_match_string(pattern, basename)) { + gchar *filename; + + filename = g_build_filename(dirname, + basename, + NULL); + do_edit(filename); + g_free(filename); + } + } + + g_pattern_spec_free(pattern); + g_dir_close(dir); + } + + g_free(dirname); + } else { + do_edit(*str ? str : NULL); + } return &states.start; } -- cgit v1.2.3