octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Selective history search with arrow keys


From: Keith Goodman
Subject: Re: Selective history search with arrow keys
Date: Sat, 23 Apr 2005 14:57:05 -0500

On 4/22/05, John W. Eaton <address@hidden> wrote:
> On 22-Apr-2005, Keith Goodman <address@hidden> wrote:
> 
> | I didn't word my question well. What I was trying to ask is if it is
> | possible to make this a default feature in octave. If it's a default
> | feature octave shouldn't touch the .inputrc file.
> 
> Octave already includes a function called read_readline_init_file, so
> I suppose we could add something like
> 
>   read_readline_init_file (sprintf ("%s%s%s", startupfiledir, filesep, 
> "inputrc"));
> 
> to the system-wide octaverc file (one is already installed, but I
> think it is empty except for a comment), and then also install a
> default inputrc file that contains the lines I sent earlier.  Would
> you like to submit a patch that does that?
> 
> jwe
> 


I modified the system-wide octaverc file to configure Octave's
line-input editing (readline). The default behavior when the up and
down arrows are pressed is now to search forwards and backwards in
Octave's history for commands that begin with the characters that
appear on the command line when the arrows are pressed.

If your Octave history is

1 a = sum(x);
2 b = prod(x);
3 all(x);
4 c = cumsum(x);
5 d = c/a;

then typing a at the command prompt followed by the up arrow will
place all(x) on the command line. Hitting the up arrow a second time
will place a = sum(x) on the command line. Typing a = followed by the
up arrow will return a = sum(x). The down arrow searches in the
opposite direction.

The configuration of readline occurs when octaverc loads the file
inputrc, which resides in Octave's startup directory (the same
directory as octaverc), using the Octave command
read_readline_init_file.

The patch (against 2.9.2) for octaverc is

%%% octaverc patch (start) %%%

***************
*** 2,4 ****
--- 2,8 ----
  ##
  ## This file should contain any commands that should be executed each
  ## time Octave starts for every user at this site.
+
+ # Configure readline using the file inputrc in the Octave startup directory
+ startupfiledir = octave_config_info ('startupfiledir');
+ read_readline_init_file (sprintf ("%s%s%s", startupfiledir, filesep,
"inputrc"));

%%% octaverc patch (end) %%%

inputrc is a new file that resides in the same directory as octaverc
(octave-2.9.2/scripts/startup/)

The configuration is for keys in ANSI mode. I can also configure the
keys for keypad mode (what is that?) 
http://www.faqs.org/docs/bashman/bashref_92.html#SEC99

%%% inputrc (start) %%%

# This file configures the behavior of line-input editing for all
# Octave users. Octave uses the Gnu Readline library for input-line
# editing.
#
# For information about the Gnu Readline library see
# http://directory.fsf.org/readline.html


# Search through the Octave history of commands for commands that
# begin with the same characters that appear on the command line when
# the up arrow is pressed to search backwards in history or the down
# arrow is pressed to search forwards.
#
"\e[A": history-search-backward
"\e[B": history-search-forward

%%% inputrc (end) %%%

The patch (against 2.9.2) for Makefile.in is (I don't know where
fcnfiledir and localfcnfiledir point but since octaverc is installed
in both places I installed inputrc in both places as well. Please
correct me if this is wrong.)

%%% Makefile.in (start) %%%

*************** install install-strip:
*** 37,42 ****
--- 37,47 ----
          $(INSTALL_DATA) $(srcdir)/octaverc \
            $(DESTDIR)$(fcnfiledir)/$(script_sub_dir)/octaverc; \
        fi
+       if test -f $(DESTDIR)$(fcnfiledir)/$(script_sub_dir)/inputrc;
then true; \
+       else \
+         $(INSTALL_DATA) $(srcdir)/inputrc \
+           $(DESTDIR)$(fcnfiledir)/$(script_sub_dir)/inputrc; \
+       fi
        $(top_srcdir)/mkinstalldirs
$(DESTDIR)$(localfcnfiledir)/$(script_sub_dir)
        if test -f $(DESTDIR)$(localfcnfiledir)/$(script_sub_dir)/octaverc; \
        then true; \
*************** install install-strip:
*** 44,49 ****
--- 49,60 ----
          $(INSTALL_DATA) $(srcdir)/octaverc \
            $(DESTDIR)$(localfcnfiledir)/$(script_sub_dir)/octaverc; \
        fi
+       if test -f $(DESTDIR)$(localfcnfiledir)/$(script_sub_dir)/inputrc; \
+       then true; \
+       else \
+         $(INSTALL_DATA) $(srcdir)/inputrc \
+           $(DESTDIR)$(localfcnfiledir)/$(script_sub_dir)/inputrc; \
+       fi
  #     for f in $(FCN_FILES_NO_DIR); do \
  #       rm -f $(DESTDIR)$(fcnfiledir)/$(script_sub_dir)/$$f; \
  #       $(INSTALL_DATA) $(srcdir)/$$f
$(DESTDIR)$(fcnfiledir)/$(script_sub_dir)/$$f; \

%%% Makefile.in (end) %%%

I may also need to patch the Octave documentation. For instance here:
http://www.octave.org/doc/octave_3.html#SEC27. I'll wait to see if I
need to make change to what I have so far.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]