summary refs log tree commit diff stats
path: root/compiler/renderer.nim
Commit message (Expand)AuthorAgeFilesLines
* fixes #1144Araq2014-06-301-12/+13
* new concurrency model: first steps; shared is not a keyword anymoreAraq2014-04-141-6/+0
* merged better html links #850Araq2014-04-081-11/+17
* implements ``distinct with/without X, Y``Zahary Karadjov2014-03-201-3/+12
* don't produce nested indents for nested stmt listsAraq2014-03-041-7/+10
* vm2: new representation of registersAraq2014-02-211-1/+1
* renderer knows about nkStaticTy and nkTypeClassTyAraq2014-01-231-0/+23
* next steps for closure iteratorsAraq2014-01-221-0/+5
* 'nil' as a statement is deprecated, use an empty 'discard' insteadAraq2014-01-191-4/+4
* bugfix: renderer supports 'ptr' etc. as type constraintAraq2014-01-121-4/+5
* case consistency: next stepsAraq2013-12-291-30/+30
* case consistency part 4Araq2013-12-271-10/+10
* case consistency part 1Araq2013-12-271-4/+4
* new VM: globals kinda workAraq2013-12-131-3/+7
* implemented 'import a as b'Araq2013-09-241-0/+6
* bugfix: 'not x of y' requires ()Araq2013-08-301-3/+9
* bugfix: rendering of typ|typ2Araq2013-06-271-8/+16
* completed expr/stmt unificationAraq2013-05-031-3/+2
* next steps for the new parser/grammarAraq2013-04-201-2/+2
* Removes executable bit for text files.Grzegorz Adam Hankiewicz2013-03-161-0/+0
* first steps to implement object construction expressionsAraq2013-03-071-2/+2
* fixes #293Araq2013-01-081-4/+3
* implemented 'import except'Araq2012-11-281-17/+16
* first steps for the 'export' featureAraq2012-11-281-0/+15
* made 'shared' a keywordAraq2012-11-221-1/+16
* syntax compatibility between do blocks and stmt blocksZahary Karadjov2012-10-041-1/+0
* implements/fixes #195Araq2012-09-221-1/+2
* proc bodies can be expressions with a typeAraq2012-09-221-0/+4
* term rewriting macros fully implemented; still buggyAraq2012-09-031-6/+11
* next steps towards term rewriting macros; simple examples workAraq2012-08-301-4/+5
* first steps towards term rewriting macrosAraq2012-08-301-6/+17
* parameter passing works the same for macros and templates; use callsite magic...Araq2012-08-281-1/+1
* distinguish properly between nkOpen and nkClosedSymChoiceAraq2012-08-261-2/+3
* made compiler more robust for idetools; implemented idetools.usagesAraq2012-07-301-1/+3
* ';' now valid for parameter listsAraq2012-07-111-4/+9
* added devel/logging; weakrefs test; next steps for proper unsigned supportAraq2012-07-051-2/+2
* docgen2 improvementsAraq2012-06-231-2/+16
* docgen2 improvementsAraq2012-06-231-9/+32
* better support for unsigned integers.Zahary Karadjov2012-06-111-0/+6
* added system.||; lacks runtime supportAraq2012-05-231-1/+1
* Merge branch 'master' of github.com:Araq/Nimrod into upstreamZahary Karadjov2012-04-101-1/+5
|\
| * fixed another docgen bug; initial mongodb wrapperAraq2012-04-061-1/+5
* | when expressions, proper rendering for nkDo and nkLambda and parser support f...Zahary Karadjov2012-04-051-5/+21
|/
* implemented 'static'; macros do not work anymoreAraq2012-03-151-0/+16
* `do' keyword in the grammar for lambda blocksZahary Karadjov2012-02-101-2/+2
* version 0.8.14Araq2012-02-091-0/+3
* further steps to closure supportAraq2012-02-061-2/+2
* pragma on/off improvements; endb rewrittenAraq2012-01-281-0/+2
* pragma blocks; fixed line information issue with user defined assertionsAraq2012-01-171-0/+11
* year 2012 for most copyright headersAraq2012-01-021-1/+1
espace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os
from curses import *
from curses.ascii import *
from inspect import getargspec, ismethod

from ranger import RANGERDIR
from ranger.gui.widgets import console_mode as cmode
from ranger.container.bookmarks import ALLOWED_KEYS as ALLOWED_BOOKMARK_KEYS

class Wrapper(object):
	def __init__(self, firstattr):
		self.__firstattr__ = firstattr

	def __getattr__(self, attr):
		if attr.startswith('_'):
			raise AttributeError
		def wrapper(*real_args, **real_keywords):
			def function(command_argument):
				args, kws = real_args, real_keywords
				number = command_argument.n
				obj = getattr(command_argument, self.__firstattr__)
				fnc = getattr(obj, attr)
				if number is not None:
					args, kws = replace_narg(number, fnc, args, kws)
				return fnc(*args, **kws)
			return function
		return wrapper

# fm.enter_dir('~') is translated into lambda arg: arg.fm.enter_dir('~')
# this makes things like this possible:
# bind('gh', fm.enter_dir('~'))
#
# but NOT: (note the 2 dots)
# bind('H', fm.history.go(-1))
#
# for something like that, use the long version:
# bind('H', lambda arg: arg.fm.history.go(-1))
#
# If the method has an argument named "narg", pressing a number before
# the key will pass that number as the narg argument. If you want the
# same behaviour in a custom lambda function, you can write:
# bind('gg', fm.move_pointer(absolute=0))
# as:
# bind('gg', lambda arg: narg(arg.n, arg.fm.move_pointer, absolute=0))

fm = Wrapper('fm')
wdg = Wrapper('wdg')


NARG_KEYWORD = 'narg'

def narg(number_, function_, *args_, **keywords_):
	"""
	This applies the replace_narg function to the arguments and keywords
	and directly runs this function.

	Example:
	def foo(xyz, narg): return hash((xyz, narg))

	narg(50, foo, 123) == foo(123, narg=50)
	"""
	args, keywords = replace_narg(number_, function_, args_, keywords_)
	print(args, keywords)
	return function_(*args, **keywords)

def replace_narg(number, function, args, keywords):
	"""
	This function returns (args, keywords) with one little change:
	if <function> has a named argument called "narg", args and keywords
	will be modified so that the value of "narg" will be <number>.

	def foo(xyz, narg): pass

	replace_narg(666, foo, (), {'narg': 10, 'xyz': 5})
	=> (), {'narg': 666, 'xyz': 5}

	replace_narg(666, foo, (1, 2), {})
	=> (1, 666), {}
	"""
	argspec = getargspec(function).args
	if NARG_KEYWORD in argspec:
		try:
			# is narg in args?
			args = list(args)
			index = argspec.index(NARG_KEYWORD)
			if ismethod(function):
				index -= 1  # because of 'self'
			args[index] = number
		except (ValueError, IndexError):
			# is narg in keywords?
			keywords = dict(keywords)
			keywords[NARG_KEYWORD] = number
	return args, keywords