summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--doc/ranger.18
-rw-r--r--doc/ranger.pod4
-rw-r--r--ranger/api/commands.py40
-rwxr-xr-xranger/config/commands.py9
-rw-r--r--ranger/config/rc.conf26
5 files changed, 71 insertions, 16 deletions
diff --git a/doc/ranger.1 b/doc/ranger.1
index 46ede8c6..d8ca79e3 100644
--- a/doc/ranger.1
+++ b/doc/ranger.1
@@ -133,7 +133,7 @@
 .\" ========================================================================
 .\"
 .IX Title "RANGER 1"
-.TH RANGER 1 "ranger-1.7.2" "03/25/2016" "ranger manual"
+.TH RANGER 1 "ranger-1.7.2" "04/03/2016" "ranger manual"
 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
 .\" way too many mistakes in technical documents.
 .if n .ad l
@@ -633,6 +633,12 @@ fly with the command \fB:set option value\fR.  Examples:
 \& set show_hidden true
 .Ve
 .PP
+Toggling options can be done with:
+.PP
+.Vb 1
+\& set show_hidden!
+.Ve
+.PP
 The different types of settings and an example for each type:
 .PP
 .Vb 7
diff --git a/doc/ranger.pod b/doc/ranger.pod
index fd29c6fd..6d798b5a 100644
--- a/doc/ranger.pod
+++ b/doc/ranger.pod
@@ -606,6 +606,10 @@ fly with the command B<:set option value>.  Examples:
  set column_ratios 1,2,3
  set show_hidden true
 
+Toggling options can be done with:
+
+ set show_hidden!
+
 The different types of settings and an example for each type:
 
  setting type   | example values
diff --git a/ranger/api/commands.py b/ranger/api/commands.py
index a20adecb..c3e0a59a 100644
--- a/ranger/api/commands.py
+++ b/ranger/api/commands.py
@@ -152,6 +152,27 @@ class Command(FileManagerAware):
         return ''.join([self._tabinsert_left, word, self._tabinsert_right])
 
     def parse_setting_line(self):
+        """
+        Parses the command line argument that is passed to the `:set` command.
+        Returns [option, value, name_complete].
+
+        Can parse incomplete lines too, and `name_complete` is a boolean
+        indicating whether the option name looks like it's completed or
+        unfinished.  This is useful for generating tab completions.
+
+        >>> Command("set foo=bar").parse_setting_line()
+        ['foo', 'bar', True]
+        >>> Command("set foo").parse_setting_line()
+        ['foo', '', False]
+        >>> Command("set foo=").parse_setting_line()
+        ['foo', '', True]
+        >>> Command("set foo ").parse_setting_line()
+        ['foo', '', True]
+        >>> Command("set myoption myvalue").parse_setting_line()
+        ['myoption', 'myvalue', True]
+        >>> Command("set").parse_setting_line()
+        ['', '', False]
+        """
         if self._setting_line is not None:
             return self._setting_line
         match = _SETTINGS_RE.match(self.rest(1))
@@ -163,6 +184,25 @@ class Command(FileManagerAware):
         self._setting_line = result
         return result
 
+    def parse_setting_line_v2(self):
+        """
+        Parses the command line argument that is passed to the `:set` command.
+        Returns [option, value, name_complete, toggle].
+
+        >>> Command("set foo=bar").parse_setting_line_v2()
+        ['foo', 'bar', True, False]
+        >>> Command("set foo!").parse_setting_line_v2()
+        ['foo', '', True, True]
+        """
+        option, value, name_complete = self.parse_setting_line()
+        if len(option) >= 2 and option[-1] == '!':
+            toggle = True
+            option = option[:-1]
+            name_complete = True
+        else:
+            toggle = False
+        return [option, value, name_complete, toggle]
+
     def parse_flags(self):
         """Finds and returns flags in the command
 
diff --git a/ranger/config/commands.py b/ranger/config/commands.py
index c41bfcb6..4d00b4c8 100755
--- a/ranger/config/commands.py
+++ b/ranger/config/commands.py
@@ -336,12 +336,17 @@ class set_(Command):
     """:set <option name>=<python expression>
 
     Gives an option a new value.
+
+    Use `:set <option>!` to toggle or cycle it, e.g. `:set flush_input!`
     """
     name = 'set'  # don't override the builtin set class
     def execute(self):
         name = self.arg(1)
-        name, value, _ = self.parse_setting_line()
-        self.fm.set_option_from_string(name, value)
+        name, value, _, toggle = self.parse_setting_line_v2()
+        if toggle:
+            self.fm.toggle_option(name)
+        else:
+            self.fm.set_option_from_string(name, value)
 
     def tab(self, tabnum):
         from ranger.gui.colorscheme import get_all_colorschemes
diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf
index 44692d79..25972904 100644
--- a/ranger/config/rc.conf
+++ b/ranger/config/rc.conf
@@ -412,7 +412,7 @@ map <a-8>     tab_open 8
 map <a-9>     tab_open 9
 
 # Sorting
-map or toggle_option sort_reverse
+map or set sort_reverse!
 map oz set sort=random
 map os chain set sort=size;      set sort_reverse=False
 map ob chain set sort=basename;  set sort_reverse=False
@@ -435,18 +435,18 @@ map oE chain set sort=extension; set sort_reverse=True
 map dc get_cumulative_size
 
 # Settings
-map zc    toggle_option collapse_preview
-map zd    toggle_option sort_directories_first
-map zh    toggle_option show_hidden
-map <C-h> toggle_option show_hidden
-map zI    toggle_option flushinput
-map zi    toggle_option preview_images
-map zm    toggle_option mouse_enabled
-map zp    toggle_option preview_files
-map zP    toggle_option preview_directories
-map zs    toggle_option sort_case_insensitive
-map zu    toggle_option autoupdate_cumulative_size
-map zv    toggle_option use_preview_script
+map zc    set collapse_preview!
+map zd    set sort_directories_first!
+map zh    set show_hidden!
+map <C-h> set show_hidden!
+map zI    set flushinput!
+map zi    set preview_images!
+map zm    set mouse_enabled!
+map zp    set preview_files!
+map zP    set preview_directories!
+map zs    set sort_case_insensitive!
+map zu    set autoupdate_cumulative_size!
+map zv    set use_preview_script!
 map zf    console filter%space
 
 # Bookmarks