- Rework input parsing in the file browser to be more flexible.
New function parse_browser_input(); changes to do_browser().
(DLR)
+ - Allow tab completion of directories at the "Go To Directory"
+ prompt. Changes to do_browser(), do_insertfile(),
+ do_writeout(), cwd_tab_completion(), input_tab(),
+ get_prompt_string(), do_prompt(), search_init(), do_replace(),
+ do_gotolinecolumn(), and do_int_spell_fix. (DLR)
- browser.c:
do_browser()
- Properly set currshortcut back to the file browser shortcut
case NANO_GOTOLINE_KEY:
curs_set(1);
- j = do_prompt(FALSE, gotodir_list, "",
+ j = do_prompt(TRUE,
+#ifndef DISABLE_TABCOMP
+ FALSE,
+#endif
+ gotodir_list, "",
#ifndef NANO_TINY
NULL,
#endif
#endif
i = do_prompt(TRUE,
+#ifndef DISABLE_TABCOMP
+ TRUE,
+#endif
#ifndef NANO_TINY
execute ? extcmd_list :
#endif
* and we're at the "Write File" prompt, disable tab
* completion. */
i = do_prompt(!ISSET(RESTRICTED) ||
- openfile->filename[0] == '\0', writefile_list, ans,
+ openfile->filename[0] == '\0',
+#ifndef DISABLE_TABCOMP
+ TRUE,
+#endif
+ writefile_list, ans,
#ifndef NANO_TINY
NULL, "%s%s%s", _(msg), formatstr, backupstr
#else
/* We consider the first buflen characters of buf for filename tab
* completion. */
-char **cwd_tab_completion(const char *buf, size_t *num_matches, size_t
- buflen)
+char **cwd_tab_completion(const char *buf, bool allow_files, size_t
+ *num_matches, size_t buflen)
{
char *dirname = mallocstrcpy(NULL, buf), *filename;
#ifndef DISABLE_OPERATINGDIR
filenamelen = strlen(filename);
while ((nextdir = readdir(dir)) != NULL) {
+ bool skip_match = FALSE;
+
#ifdef DEBUG
fprintf(stderr, "Comparing \'%s\'\n", nextdir->d_name);
#endif
/* Cool, found a match. Add it to the list. This makes a
* lot more sense to me (Chris) this way... */
+ char *tmp = charalloc(strlen(dirname) +
+ strlen(nextdir->d_name) + 1);
+ sprintf(tmp, "%s%s", dirname, nextdir->d_name);
+
#ifndef DISABLE_OPERATINGDIR
/* ...unless the match exists outside the operating
- * directory, in which case just go to the next match. To
- * properly do operating directory checking, we have to add
- * the directory name to the beginning of the proposed match
- * before we check it. */
- char *tmp2 = charalloc(strlen(dirname) +
- strlen(nextdir->d_name) + 1);
+ * directory, in which case just go to the next match. */
+ if (check_operating_dir(tmp, TRUE))
+ skip_match = TRUE;
+#endif
+
+ /* ...or unless the match isn't a directory and allow_files
+ * isn't set, in which case just go to the next match. */
+ if (!allow_files && !is_dir(tmp)) {
+ skip_match = TRUE;
+
+ free(tmp);
- sprintf(tmp2, "%s%s", dirname, nextdir->d_name);
- if (check_operating_dir(tmp2, TRUE)) {
- free(tmp2);
+ if (skip_match)
continue;
- }
- free(tmp2);
-#endif
matches = (char **)nrealloc(matches, (*num_matches + 1) *
sizeof(char *));
/* Do tab completion. place refers to how much the statusbar cursor
* position should be advanced. */
-char *input_tab(char *buf, size_t *place, bool *lastwastab, bool *list)
+char *input_tab(char *buf, bool allow_files, size_t *place, bool
+ *lastwastab, bool *list)
{
size_t num_matches = 0;
char **matches = NULL;
/* Match against files relative to the current working directory. */
if (matches == NULL)
- matches = cwd_tab_completion(buf, &num_matches, *place);
+ matches = cwd_tab_completion(buf, allow_files, &num_matches,
+ *place);
if (num_matches <= 0)
beep();
/* Get a string of input at the statusbar prompt. This should only be
* called from do_prompt(). */
-int get_prompt_string(bool allow_tabs, const char *curranswer,
+int get_prompt_string(bool allow_tabs,
+#ifndef DISABLE_TABCOMP
+ bool allow_files,
+#endif
+ const char *curranswer,
#ifndef NANO_TINY
filestruct **history_list,
#endif
} else
#endif /* !NANO_TINY */
if (allow_tabs)
- answer = input_tab(answer, &statusbar_x, &tabbed,
- list);
+ answer = input_tab(answer, allow_files,
+ &statusbar_x, &tabbed, list);
update_statusbar_line(answer, statusbar_x);
break;
* curranswer is any editable text that we want to put up by default.
*
* The allow_tabs parameter indicates whether we should allow tabs to be
- * interpreted. */
-int do_prompt(bool allow_tabs, const shortcut *s, const char
- *curranswer,
+ * interpreted. The allow_files parameter indicates whether we should
+ * allow all files (as opposed to just directories) to be tab
+ * completed. */
+int do_prompt(bool allow_tabs,
+#ifndef DISABLE_TABCOMP
+ bool allow_files,
+#endif
+ const shortcut *s, const char *curranswer,
#ifndef NANO_TINY
filestruct **history_list,
#endif
va_end(ap);
null_at(&prompt, actual_x(prompt, COLS - 4));
- retval = get_prompt_string(allow_tabs, curranswer,
+ retval = get_prompt_string(allow_tabs,
+#ifndef DISABLE_TABCOMP
+ allow_files,
+#endif
+ curranswer,
#ifndef NANO_TINY
- history_list,
+ history_list,
#endif
- s
+ s
#ifndef DISABLE_TABCOMP
- , &list
+ , &list
#endif
- );
+ );
free(prompt);
prompt = NULL;
#ifndef DISABLE_TABCOMP
char **username_tab_completion(const char *buf, size_t *num_matches,
size_t buflen);
-char **cwd_tab_completion(const char *buf, size_t *num_matches, size_t
- buflen);
-char *input_tab(char *buf, size_t *place, bool *lastwastab, bool *list);
+char **cwd_tab_completion(const char *buf, bool allow_files, size_t
+ *num_matches, size_t buflen);
+char *input_tab(char *buf, bool allow_files, size_t *place, bool
+ *lastwastab, bool *list);
#endif
const char *tail(const char *foo);
#if !defined(NANO_TINY) && defined(ENABLE_NANORC)
void update_statusbar_line(const char *curranswer, size_t index);
void reset_statusbar_cursor(void);
bool need_statusbar_horizontal_update(size_t old_pww);
-int get_prompt_string(bool allow_tabs, const char *curranswer,
+int get_prompt_string(bool allow_tabs,
+#ifndef DISABLE_TABCOMP
+ bool allow_files,
+#endif
+ const char *curranswer,
#ifndef NANO_TINY
filestruct **history_list,
#endif
, bool *list
#endif
);
-int do_prompt(bool allow_tabs, const shortcut *s, const char
- *curranswer,
+int do_prompt(bool allow_tabs,
+#ifndef DISABLE_TABCOMP
+ bool allow_files,
+#endif
+ const shortcut *s, const char *curranswer,
#ifndef NANO_TINY
filestruct **history_list,
#endif
buf = mallocstrcpy(NULL, "");
/* This is now one simple call. It just does a lot. */
- i = do_prompt(FALSE, replacing ? replace_list : whereis_list,
- backupstring,
+ i = do_prompt(FALSE,
+#ifndef DISABLE_TABCOMP
+ TRUE,
+#endif
+ replacing ? replace_list : whereis_list, backupstring,
#ifndef NANO_TINY
&search_history,
#endif
last_replace = mallocstrcpy(last_replace, "");
- i = do_prompt(FALSE, replace_list_2, last_replace,
+ i = do_prompt(FALSE,
+#ifndef DISABLE_TABCOMP
+ TRUE,
+#endif
+ replace_list_2, last_replace,
#ifndef NANO_TINY
&replace_history,
#endif
char *ans = mallocstrcpy(NULL, answer);
/* Ask for it. */
- int i = do_prompt(FALSE, gotoline_list, use_answer ? ans : "",
+ int i = do_prompt(FALSE,
+#ifndef DISABLE_TABCOMP
+ TRUE,
+#endif
+ gotoline_list, use_answer ? ans : "",
#ifndef NANO_TINY
NULL,
#endif
do_replace_highlight(TRUE, exp_word);
/* Allow all instances of the word to be corrected. */
- canceled = (do_prompt(FALSE, spell_list, word,
+ canceled = (do_prompt(FALSE,
+#ifndef DISABLE_TABCOMP
+ TRUE,
+#endif
+ spell_list, word,
#ifndef NANO_TINY
- NULL,
+ NULL,
#endif
- _("Edit a replacement")) == -1);
+ _("Edit a replacement")) == -1);
do_replace_highlight(FALSE, exp_word);