Skip to content

Commit

Permalink
Merge branch 'linemode'
Browse files Browse the repository at this point in the history
  • Loading branch information
hut committed Dec 5, 2014
2 parents 5c97716 + 8e0e465 commit 807402c
Show file tree
Hide file tree
Showing 12 changed files with 566 additions and 8 deletions.
61 changes: 60 additions & 1 deletion doc/ranger.1
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
.\" ========================================================================
.\"
.IX Title "RANGER 1"
.TH RANGER 1 "ranger-1.6.1" "10/31/2014" "ranger manual"
.TH RANGER 1 "ranger-1.6.1" "12/05/2014" "ranger manual"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
Expand Down Expand Up @@ -539,6 +539,11 @@ Go to the next or previous tab. You can also use \s-1TAB\s0 and \s-1SHIFT+TAB\s0
.IP "gc, ^W" 14
.IX Item "gc, ^W"
Close the current tab. The last tab cannot be closed this way.
.IP "M" 14
.IX Item "M"
A key chain that allows you to quickly change the line mode of all the files of
the current directory. For a more permanent solution, use the command
\&\*(L"default_linemode\*(R" in your rc.conf.
.SS "READLINE-LIKE \s-1BINDINGS IN THE CONSOLE\s0"
.IX Subsection "READLINE-LIKE BINDINGS IN THE CONSOLE"
.IP "^B, ^F" 14
Expand Down Expand Up @@ -684,6 +689,11 @@ How many directory changes should be kept in history?
.IP "mouse_enabled [bool] <zm>" 4
.IX Item "mouse_enabled [bool] <zm>"
Enable mouse input?
.IP "papermanager_deep_search [bool]" 4
.IX Item "papermanager_deep_search [bool]"
When the paper manager module looks for metadata, should it only look for a
\&\*(L".paperinfo\*(R" file in the current directory, or do a deep search and check all
directories above the current one as well?
.IP "padding_right [bool]" 4
.IX Item "padding_right [bool]"
When collapse_preview is on and there is no preview, should there remain a
Expand Down Expand Up @@ -798,18 +808,25 @@ ranger. For your convenience, this is a list of the \*(L"public\*(R" commands i
\& copypmap key newkey [newkey2...]
\& copytmap key newkey [newkey2...]
\& cunmap keys...
\& default_linemode [path=regexp | tag=tags] linemodename
\& delete
\& edit [filename]
\& eval [\-q] python_code
\& filter [string]
\& find pattern
\& grep pattern
\& linemode linemodename
\& load_copy_buffer
\& map key command
\& mark pattern
\& mark_tag [tags]
\& mkdir dirname
\& open_with [application] [flags] [mode]
\& paper
\& paper_authors [authors]
\& paper_title [title]
\& paper_url [url]
\& paper_year [year]
\& pmap key command
\& punmap keys...
\& quit
Expand Down Expand Up @@ -898,6 +915,20 @@ See \f(CW\*(C`copymap\*(C'\fR
.IP "cunmap [\fIkeys...\fR]" 2
.IX Item "cunmap [keys...]"
Removes key mappings of the console. Works like the \f(CW\*(C`unmap\*(C'\fR command.
.IP "default_linemode [\fIpath=regexp\fR | \fItag=tags\fR] \fIlinemodename\fR" 2
.IX Item "default_linemode [path=regexp | tag=tags] linemodename"
Sets the default linemode. See \fIlinemode\fR command.
.Sp
Examples:
.Sp
Set the global default linemode to \*(L"permissions\*(R":
:default_linemode permissions
.Sp
Set the default linemode to \*(L"permissions\*(R" for all files tagged with \*(L"p\*(R" or \*(L"P\*(R":
:default_linemode tag=pP permissions
.Sp
Set the default linemode for all files in ~/books/ to \*(L"papertitle\*(R":
:default_linemode path=/home/.*?/books/.* papertitle
.IP "delete" 2
.IX Item "delete"
Destroy all files in the selection with a roundhouse kick. ranger will ask for
Expand Down Expand Up @@ -932,6 +963,16 @@ This command is based on the \fIscout\fR command and supports all of its options
.IP "grep \fIpattern\fR" 2
.IX Item "grep pattern"
Looks for a string in all marked files or directories.
.IP "linemode \fIlinemodename\fR" 2
.IX Item "linemode linemodename"
Sets the linemode of all files in the current directory. The linemode may be:
.Sp
.Vb 4
\& "filename": display each line as "<basename>...<size>"
\& "permissions": display each line as "<permissions> <owner> <group> <basename>"
\& "papertitle": display metadata from .paperinfo files if available, fall back
\& to the "filename" linemode if no metadata was found. See :paper commands.
.Ve
.IP "load_copy_buffer" 2
.IX Item "load_copy_buffer"
Load the copy buffer from \fI~/.config/ranger/copy_buffer\fR. This can be used to
Expand Down Expand Up @@ -968,6 +1009,24 @@ of applications is generated by the external file opener \*(L"rifle\*(R" and can
displayed when pressing \*(L"r\*(R" in ranger.
.Sp
Note that if you specify an application, the mode is ignored.
.IP "paper" 2
.IX Item "paper"
This command opens a series of commands on the console that will ask the user
to input metadata about the current file. This is used by the paper manager
module of ranger and can be later displayed in ranger, for example by setting
the option \*(L"linemode\*(R" to \*(L"papertitle\*(R".
.IP "paper_authors \fIauthors\fR" 2
.IX Item "paper_authors authors"
Tells the paper manager to set/update the authors of the current file
.IP "paper_title \fItitle\fR" 2
.IX Item "paper_title title"
Tells the paper manager to set/update the title of the current file
.IP "paper_url \fIurl\fR" 2
.IX Item "paper_url url"
Tells the paper manager to set/update the url of the current file
.IP "paper_year \fIyear\fR" 2
.IX Item "paper_year year"
Tells the paper manager to set/update the year of the current file
.IP "pmap \fIkey\fR \fIcommand\fR" 2
.IX Item "pmap key command"
Binds keys for the pager. Works like the \f(CW\*(C`map\*(C'\fR command.
Expand Down
66 changes: 66 additions & 0 deletions doc/ranger.pod
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,12 @@ Go to the next or previous tab. You can also use TAB and SHIFT+TAB instead.

Close the current tab. The last tab cannot be closed this way.

=item M

A key chain that allows you to quickly change the line mode of all the files of
the current directory. For a more permanent solution, use the command
"default_linemode" in your rc.conf.

=back

=head2 READLINE-LIKE BINDINGS IN THE CONSOLE
Expand Down Expand Up @@ -674,6 +680,12 @@ How many directory changes should be kept in history?

Enable mouse input?

=item papermanager_deep_search [bool]

When the paper manager module looks for metadata, should it only look for a
".paperinfo" file in the current directory, or do a deep search and check all
directories above the current one as well?

=item padding_right [bool]

When collapse_preview is on and there is no preview, should there remain a
Expand Down Expand Up @@ -813,18 +825,25 @@ ranger. For your convenience, this is a list of the "public" commands including
copypmap key newkey [newkey2...]
copytmap key newkey [newkey2...]
cunmap keys...
default_linemode [path=regexp | tag=tags] linemodename
delete
edit [filename]
eval [-q] python_code
filter [string]
find pattern
grep pattern
linemode linemodename
load_copy_buffer
map key command
mark pattern
mark_tag [tags]
mkdir dirname
open_with [application] [flags] [mode]
paper
paper_authors [authors]
paper_title [title]
paper_url [url]
paper_year [year]
pmap key command
punmap keys...
quit
Expand Down Expand Up @@ -927,6 +946,21 @@ See C<copymap>

Removes key mappings of the console. Works like the C<unmap> command.

=item default_linemode [I<path=regexp> | I<tag=tags>] I<linemodename>

Sets the default linemode. See I<linemode> command.

Examples:

Set the global default linemode to "permissions":
:default_linemode permissions

Set the default linemode to "permissions" for all files tagged with "p" or "P":
:default_linemode tag=pP permissions

Set the default linemode for all files in ~/books/ to "papertitle":
:default_linemode path=/home/.*?/books/.* papertitle

=item delete

Destroy all files in the selection with a roundhouse kick. ranger will ask for
Expand Down Expand Up @@ -967,6 +1001,15 @@ This command is based on the I<scout> command and supports all of its options.

Looks for a string in all marked files or directories.

=item linemode I<linemodename>

Sets the linemode of all files in the current directory. The linemode may be:

"filename": display each line as "<basename>...<size>"
"permissions": display each line as "<permissions> <owner> <group> <basename>"
"papertitle": display metadata from .paperinfo files if available, fall back
to the "filename" linemode if no metadata was found. See :paper commands.

=item load_copy_buffer

Load the copy buffer from F<~/.config/ranger/copy_buffer>. This can be used to
Expand Down Expand Up @@ -1009,6 +1052,29 @@ displayed when pressing "r" in ranger.

Note that if you specify an application, the mode is ignored.

=item paper

This command opens a series of commands on the console that will ask the user
to input metadata about the current file. This is used by the paper manager
module of ranger and can be later displayed in ranger, for example by setting
the option "linemode" to "papertitle".

=item paper_authors I<authors>

Tells the paper manager to set/update the authors of the current file

=item paper_title I<title>

Tells the paper manager to set/update the title of the current file

=item paper_url I<url>

Tells the paper manager to set/update the url of the current file

=item paper_year I<year>

Tells the paper manager to set/update the year of the current file

=item pmap I<key> I<command>

Binds keys for the pager. Works like the C<map> command.
Expand Down
122 changes: 122 additions & 0 deletions ranger/config/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,43 @@ def execute(self):
self.fm.set_option_from_string(name, value, tags=tags)


class default_linemode(Command):
def execute(self):
import re
from ranger.container.fsobject import POSSIBLE_LINEMODES

if len(self.args) < 2:
self.fm.notify("Usage: default_linemode [path=<regexp> | tag=<tag(s)>] <linemode>", bad=True)

# Extract options like "path=..." or "tag=..." from the command line
arg1 = self.arg(1)
method = "always"
argument = None
if arg1.startswith("path="):
method = "path"
argument = re.compile(arg1[5:])
self.shift()
elif arg1.startswith("tag="):
method = "tag"
argument = arg1[4:]
self.shift()

# Extract and validate the line mode from the command line
linemode = self.rest(1)
if linemode not in POSSIBLE_LINEMODES:
self.fm.notify("Invalid linemode: %s; should be %s" %
(linemode, "/".join(POSSIBLE_LINEMODES)), bad=True)

# Add the prepared entry to the fm.default_linemodes
entry = [method, argument, linemode]
self.fm.default_linemodes.appendleft(entry)

# Redraw the columns
if hasattr(self.fm.ui, "browser"):
for col in self.fm.ui.browser.columns:
col.need_redraw = True


class quit(Command):
""":quit
Expand Down Expand Up @@ -1281,3 +1318,88 @@ def execute(self):
self.fm.thisdir.flat = level
self.fm.thisdir.load_content()


# Papermanager commands
# --------------------------------
class paper(Command):
"""
:paper
This command opens a series of commands on the console that will ask the
user to input metadata about the current file. This is used by the paper
manager module of ranger and can be later displayed in ranger, for example
by setting the option "linemode" to "papertitle".
"""
_paper_console_chain = None
def execute(self):
# TODO: This sets a pseudo-global variable containing a stack of
# commands that should be opened in the console next. It's a
# work-around for ranger's lack of inherent console command chaining
# and will hopefully be implemented properly in the future.
paper._paper_console_chain = ["url", "year", "authors", "title"]

self._process_command_stack()

def _process_command_stack(self):
if paper._paper_console_chain:
key = paper._paper_console_chain.pop()
self._paper_fill_console(key)
else:
for col in self.fm.ui.browser.columns:
col.need_redraw = True

def _paper_fill_console(self, key):
paperinfo = self.fm.papermanager.get_paper_info(self.fm.thisfile.path)
if key in paperinfo and paperinfo[key]:
existing_value = paperinfo[key]
else:
existing_value = ""
text = "paper_%s %s" % (key, existing_value)
self.fm.open_console(text, position=len(text))


class paper_title(paper):
"""
:paper_title <title>
Tells the paper manager to set/update the title of the current file
"""
_key = "title"

def execute(self):
update_dict = dict()
update_dict[self._key] = self.rest(1)
self.fm.papermanager.set_paper_info(self.fm.thisfile.path, update_dict)
self._process_command_stack()

def tab(self):
paperinfo = self.fm.papermanager.get_paper_info(self.fm.thisfile.path)
if paperinfo[self._key]:
return self.arg(0) + " " + paperinfo[self._key]


class paper_authors(paper_title):
"""
:paper_authors <authors>
Tells the paper manager to set/update the authors of the current file
"""
_key = "authors"


class paper_url(paper_title):
"""
:paper_url <authors>
Tells the paper manager to set/update the url of the current file
"""
_key = "url"


class paper_year(paper_title):
"""
:paper_year <authors>
Tells the paper manager to set/update the year of the current file
"""
_key = "year"
10 changes: 10 additions & 0 deletions ranger/config/rc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ set show_selection_in_titlebar true
# increases CPU load.
set idle_delay 2000

# When the paper manager module looks for metadata, should it only look for a
# ".paperinfo" file in the current directory, or do a deep search and check all
# directories above the current one as well?
set papermanager_deep_search false

# ===================================================================
# == Local Options
# ===================================================================
Expand Down Expand Up @@ -232,6 +237,11 @@ map r chain draw_possible_programs; console open_with
map f console find
map cd console cd

# Change the line mode
map Mf linemode filename
map Mp linemode permissions
map Mt linemode papertitle

# Tagging / Marking
map t tag_toggle
map ut tag_remove
Expand Down
Loading

0 comments on commit 807402c

Please sign in to comment.