summary refs log tree commit diff stats
path: root/lib/pure/asyncmacro.nim
Commit message (Expand)AuthorAgeFilesLines
...
* Remove unneeded comment #6708Anatoly Galiulin2017-11-131-3/+0
* Fix parameter types splitting in multisync macro #6708Anatoly Galiulin2017-11-091-19/+8
* work in progress: new implementation for 'a[^1]'Andreas Rumpf2017-10-291-7/+7
* revert accidentical asyncmacro changeAndreas Rumpf2017-09-211-1/+1
* introduce OnHeapNew and rename TLoc.s to TLoc.storageAndreas Rumpf2017-09-211-1/+1
* workaround so doc2 asynchttpserver works againAndreas Rumpf2017-07-261-3/+3
* Suppress "pointless conversion" hint (#6103)Yuriy Glukhov2017-07-151-0/+2
* Fixes #5738 (#6059)Yuriy Glukhov2017-07-151-3/+7
* Fixes #5995Yuriy Glukhov2017-06-181-1/+1
* Fixes regression introduced by #5739. Improves newNimNode proc.Dominik Picheta2017-05-171-1/+1
* Remove processing hints for async procs.Dominik Picheta2017-05-161-3/+0
* Async macro fixes (#5739)Yuriy Glukhov2017-05-161-20/+18
* Fixes the order in which FutureVar and return completions are made.Dominik Picheta2017-03-271-10/+17
* Add support for `Async | Sync` return types in {.multisync.} macro.Dominik Picheta2017-02-111-21/+34
* Improve error message when a `nil` future is await'ed.Dominik Picheta2017-02-091-3/+5
* Allow .async pragma on methods (#5312)Ruslan Mustakov2017-02-011-2/+2
* deprecated nativesockets.dealloc, use freeAddrInfo instead; fixed stdlib depr...Andreas Rumpf2017-01-301-3/+3
* FutureVar[T] parameters are now completed automatically.Dominik Picheta2016-09-251-8/+43
* Fixes `asyncmacro` compilation in tests.Dominik Picheta2016-09-191-2/+1
* Implements {.multisync.} pragma for async and sync proc combos.Dominik Picheta2016-09-181-0/+110
* Fixes #4170.Dominik Picheta2016-09-171-3/+1
* async: transfer all await/async macro related code to asyncmacro.nim module. ...Eugene Kabanov2016-09-031-0/+373
20:33:11 +0100 committer hut <hut@lavabit.com> 2010-01-03 20:33:11 +0100 keyapi: a different approach to passing through typed numbers' href='/akspecs/ranger/commit/ranger/keyapi.py?id=847010930a11791c87845a011cd968b2f0861155'>84701093 ^
d492db52 ^

84701093 ^

70aec44f ^

70aec44f ^








84701093 ^



d6e2900a ^
84701093 ^
d6e2900a ^
84701093 ^




d492db52 ^
84701093 ^












84701093 ^

d492db52 ^
84701093 ^








70aec44f ^
84701093 ^



d492db52 ^

84701093 ^

84701093 ^





7b4ef308 ^
84701093 ^
d492db52 ^









84701093 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
                                                                 
 



                                                                      
 






                                                                       
 
         

                          

                                        
                            
                        
                                                                            
                                                                           
 




                                              

                                            



                                                                    
                                                                      
                                                                                   
                                                        

                                                                                                   

                                                        

                              








                                                                        



                                                                      
                           
     
                                                        




                    
                         












                                                                            

                                           
                                                              








                                                                           
 



                                           

                                                          

                                          





                                                               
                                                 
                                                       









                                                               
                             
# 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.api import *
from ranger.container.bookmarks import ALLOWED_KEYS as ALLOWED_BOOKMARK_KEYS
from ranger.container.keymap import KeyMap, Direction, KeyMapWithDirections

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
				direction = command_argument.direction
				obj = getattr(command_argument, self.__firstattr__)
				fnc = getattr(obj, attr)
				if number is not None or direction is not None:
					args, kws = replace_narg(number, direction, 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(to=0))
# as:
# bind('gg', lambda arg: narg(arg.n, arg.fm.move, to=0))

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


DIRARG_KEYWORD = 'dirarg'
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_)
	return function_(*args, **keywords)

def replace_narg(number, direction, 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
	args = list(args)
	if number is not None and NARG_KEYWORD in argspec:
		try:
			# is narg in 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
	if direction is not None and DIRARG_KEYWORD in argspec:
		try:
			index = argspec.index(DIRARG_KEYWORD)
			if ismethod(function):
				index -= 1  # because of 'self'
			args[index] = direction
		except (ValueError, IndexError):
			# is narg in keywords?
			keywords = dict(keywords)
			keywords[DIRARG_KEYWORD] = direction
	return args, keywords