Vimperator recommended setting - firefox

By way of study of Vim, I have begun to use Vimperator add-on for Firefox recently.
Therefore please teach it if there is recommended setting.

Two settings are extremely useful, at least for me:
:set wildoption=auto
:set cpt=l
You can try them from vimperator command line first. After you type in the first one, you will see dynamic hints immediately, for example, if you continue to try the second command and to see what mean by 'l' . With wildoption on, you access to an item from the hint list by pressing Tab key, instead of arrow keys which would not work in most cases.
Another one I like is to set up my Bookmarks as sidebar by default, the command is:
:sidebar Bookmarks
One more trick after you have wildoptions on, you can access to FireFox menu items by typing:
:emenu [key_word]
# or
:em[tab]
where key_word is any menu key word such as Add-on.
I have several blogs on vimperator and how to set vimperator default settings.
Enjoy Vimperator. It is a great add-on for Firefox.

Skypecakes suggested b and B to switch tabs; I prefer using h and l, since there's a good chance you switch tabs more often than you scroll horizontally:
noremap l gt
noremap h gT
Calling up Vim itself with C-i in a textarea is a must. See here if you have trouble on Windows
set editor="C:/path/to/gvim.exe -f"
This is to customize how hints look in .vimperatorrc. The syntax is CSS, but you can probably figure it out without knowing it as well (I personally increase the font-size):
highlight! Hint font-family: monospace; font-size: 16px; font-weight: bold; text-transform: uppercase; color: white; background-color: red; border-color: ButtonShadow; border-width: 0px; border-style: solid; padding: 0px 1px 0px 1px;
Finally, if you set the working directory you can save URLs to that location with a simple :w<Enter>:
cd C:/Users/GGustafson/Desktop

Not really. One of the remarkable characteristics of Vim (and Vimperator) is providing a pretty decent experience with the default configuration. What I would suggest you to do is to play around with macros (q) and hinting (f), the best, IMHO, features of Vimperator.
There are numerous examples of interesting macros, being my favourite the one that opens all the images on all tabs, each expanding into a new tab with the corresponding images. Try to write it! You'll need just markers and some javascript similar to Pornzilla's "Linked Images"

I'm using Pentadactyl - which is almost the same. I find useful the following two options:
set hintkeys=0123456789abcdefghijklmnopqrstuvwxyz
set! browser.tabs.closeButtons=2
Also - suppose Your FireFox aware of wikipedia search - and suppose it is called wikipedia-en. Then here's a way to bind search selection in wikipedia to a key:
javascript <<EOF
dactyl.mulSearch = function () {
let selection = content.getSelection().toString();
dactyl.execute(":tabopen wikipedia-en " + selection);
};
EOF
:map s -js dactyl.mulSearch();
(You should put this to ~/.pentadactylrc) This search selection after You'll press s. This way You can also bind other search engines - to the same key!
Edit:
" default place for downloads:
cd ~/dwn
" lots of hints!
set hintkeys=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
" no close buttons on tabs
set! browser.tabs.closeButtons=2
" May be default hints would suit You better - but they were to small for me:
:highlight Hint font:"DejaVu Sans Mono";font-size:120%;color:red;background-color:yellow;padding:2px;
" to prevent d on the last tab from closing the window:
:set! browser.tabs.closeWindowWithLastTab=false
" encripted google - is better for hints (it has less links)
:bmark https://encrypted.google.com/search?sclient=psy&hl=en&complete=0&site=webhp&source=hp&q=%s -keyword google
set defsearch=google
" ==================
"" Cyrillic letters:
map Ф A
map И B
map С C
map В D
map У E
map А F
map П G
map Р H
map Ш I
map О J
map Л K
map Д L
map Ь M
map Т N
map Щ O
map З P
map Й Q
map К R
map Ы S
map Е T
map Г U
map М V
map Ц W
map Ч X
map Н Y
map Я Z
map ф a
map и b
map с c
map в d
map у e
map а f
map п g
map р h
map ш i
map о j
map л k
map д l
map ь m
map т n
map щ o
map з p
map й q
map к r
map ы s
map е t
map г u
map м v
map ц w
map ч x
map н y
map я z

I made some small changes. Made moving between tabs a single keystroke instead of two, since it is the most common thing I do next to clicking links and scrolling.
Also show visual indicator instead of beeping, and show the destination of the selected hyperlink in the command line instead of the status line, so that I can still see the URL of the current page at all times.
From my _vimperatorrc file:
" Mappings
map b gt
map B gT
map a B
" Options
set visualbell
set complete=hbsf
set showstatuslinks=2

I also use Pentadactyl, but the below should work with Vimperator as well. I added several commands to enable searching through different sites like DuckDuckGo and stackoverflow.
You can add a new search engine with the following command:
:display searchengines
Add the stackoverflow search engine to make the below work.
Define a new command stack to search through stackoverflow:
:command -nargs=* stack open stack-overflow <args>
Now you can search through stackoverflow to get all vimperator related questions with the following command:
:stack vimperator
Make sure to issue
:mkpentadactylrc!
to make the command available after a restart of Firefox.

"eval script in tabs
js <<EOF
function ExecScriptInTabs(filter,domjs){
tabs.allTabs.forEach(function(itm){
var ctab=gBrowser.getBrowserForTab(itm);
if(filter(ctab)){
var s=ctab.contentDocument.createElement('script')
s.textContent=domjs;
ctab.contentDocument.body.appendChild(s);
}
})
}
EOF
then you can mapping what you want
group.mappings.add(
[modes.NORMAL],
[",ds"],"skip",
function(){
ExecScriptInTabs(function(ctab){
return ctab.contentDocument.location.host.match("douban\.fm");
},"DBR.act('skip')");//skip,pause,love
}
)

If you want to save session when using Alt+F4 or qall command
Add following line to your ~/.vimperatorrc
command! qall xall

Related

In the Magellan / Nightwatch framework, how to set a CSS outline on an element?

Suppose in writing or verifying a test, the command code is:
pToggleMyCoolToggle: function () {
var selectors = this.elements;
return this
.getEl(selectors.myCoolCheckbox.selector)
.moveToEl(selectors.myCoolCheckbox.selector)
.clickEl(selectors.myCoolCheckbox.selector);
}
How can this element on the browser be shown with an outline using CSS:
outline: 3px dotted orange
by adding some code to the above command, using the methods inside of Magellan / Nightwatch?
Just use .execute
client.execute(function(){
document.getElementById('idYouWantToTarget').style.border="3px dotted orange";
})
I just found that the name selectors.myCoolCheckbox.selector is written by some amateur. It really should be paymentPage.useCreditCardRadio.selector. So the final selector states what the CSS selector is.
The line selectors = this.elements is very misleading too. selectors is not the "elements". It might be paymentPage = this.elements and paymentPage has many properties, including a useCreditCardRadio. Or it could be paymentPageElements = this.elements which means paymentPageElements is an object that contains all elements. So this example shows how bad naming affects programming, for all the people who will need to touch or edit the code in the future.
As a result, you should be able to use
var el = document.querySelector(paymentPage.useCreditCardRadio.selector);
and once you have the element, you can add the outline to it.

Attribute concatenation with multiple Theme Classes in SD app

I am creating a SD App in GX Ev3, and am working on a list.
I came across a requirement for the App and don't know how to do it.
I have to concatenate some Attributes in a String, but one of them (&Status) has to be Font Bold.
&Status + ', por ' + &User + ' em ' + &Date
Possible results:
'OK, por User1 em 01/07/2014'
'Com problema #5, por User2 em 01/07/2014'
'Por validar, por User3 em 01/07/2014'
How can I do it, so it looks like continuous text?
You can do that by using a variable based on the Html domain, and using HTML formatting for the value (i.e. "<b>OK</b>, por ...").
This will create a WebView to display the text, achieving the effect you want.
However, WebViews are unfortunately more resource-intensive than edits, so using them inside a grid is not recommended. We hope to provide a better solution soon.
I would do the HTML field as matiash suggested
But if you want other solution you could do a User Control that can help you.
In an application we have been developing for iOS we have done this using the NSAttributeString.
https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/classes/NSAttributedString_Class/Reference/Reference.html
What we did is:
&varUC = "#"+&Status +"# my middle text 1 #" + &User + "# my middle text2 #"+&Date+"#"
In our UC we separated the string by the "#" and we changed the the color and weight of those words, then remove the # when displaying the text.
For Android, we haven't done this yet, but with a quick Google search I think you should use:
how to change text color in the middle of the sentence in android
Doing a User Control for GeneXus Smart Devices is really easy ->
http://wiki.genexus.com/commwiki/servlet/hwikibypageid?15301
You can try using the tag "after" in the definition of the class, but you'll have to split the atribute.
Your best bet is to split the variables on the screen, both with distinct classes:
&Status &Text
&Status = 'OK'
&Text = ', por'+&User+' em '+&date
The css sample below is used to automatically set bold fields and (*) on the label of required fields:
.RequiredDataDescription:after
{
font-size: 11px;
font-weight: bold;
color: #333333;
content:" (*)";
}

How to implement tk scrollbar for multiple listboxes (TCL)?

I tried all sort of options but no success in implement simple scrollbar for two or more listboxes. Following is my code giving error while scrolling. I hope you guys are helping me...
scrollbar .scroll -orient v
pack .scroll -side left -fill y
listbox .lis1
pack .lis1 -side left
listbox .lis2
pack .lis2 -side left
for {set x 0} {$x < 100} {incr x} {
.lis1 insert end $x
.lis2 insert end $x
}
.lis1 configure -yscrollcommand [list .scroll set]
.lis2 configure -yscrollcommand [list .scroll set]
.scroll configure -command ".lis1 yview .lis2 yview ";
thanking you.
There are a number of examples on the Tcler's wiki, but the core principle is to use a procedure to ensure that the scrolling protocol is synchronized between the widgets. Here's an example based off that wiki page:
# Some data to scroll through
set ::items [lrepeat 10 {*}"The quick brown fox jumps over the lazy dog."]
# Some widgets that will scroll together
listbox .list1 -listvar ::items -yscrollcommand {setScroll .scroll}
listbox .list2 -listvar ::items -yscrollcommand {setScroll .scroll}
scrollbar .scroll -orient vertical -command {synchScroll {.list1 .list2} yview}
# The connectors
proc setScroll {s args} {
$s set {*}$args
{*}[$s cget -command] moveto [lindex [$s get] 0]
}
proc synchScroll {widgets args} {
foreach w $widgets {$w {*}$args}
}
# Put the GUI together
pack .list1 .scroll .list2 -side left -fill y
It's worth noting that you can also plug any other scrollable widget into this scheme; everything in Tk scrolls the same way (except with -xscrollcommand and xview for horizontal scrolling, together with a change of scrollbar orientation). Furthermore, the connectors here, unlike the ones on the wiki page, can be used with multiple groups of scrolled widgets at once; the knowledge of what is scrolled together is stored in the -command option of the scrollbar (first argument to synchScroll callback).
[EDIT]: For 8.4 and before, you need slightly different connector procedures:
# The connectors
proc setScroll {s args} {
eval [list $s set] $args
eval [$s cget -command] [list moveto [lindex [$s get] 0]]
}
proc synchScroll {widgets args} {
foreach w $widgets {eval [list $w] $args}
}
Everything else will be the same.
I know that this post is really old but I recently discovered what I think is a fairly simple solution. Instead of using the vertical scrollbar I found that I can use the slider widget. With the slider you can get the position of the slider and use that to set the yview of the listbox(es). Multiple listboxes can be scrolled simultaneously. I use vtcl to build the GUI so the code I can provide may not beimmediately obvious for those using tk wm comands. But here is the code I use. It is bound to slider motion.
set listIndex [$widget(Scale1) get]
$widget(Listbox1) yview $listIndex
$widget(Listbox2) yview $listIndex
Hope that is helpful to somebody.
If you plan to do much work in the the callback command - make a procedure to do it as that is both faster (the procedure gets byte compiled) and less likely to introduce tcl syntax problems. In this case you are trying to perform two tcl commands in the scrollbar function so you need to separate the statements using newline or a semicolon.
Calling the scrollbar set function from both listboxes will just have the second one override the first. You either need a function to merge those two or if the lists have the same lengths, just call it from one of them to set the scrollbar size and position and then update all listboxes with the scrollbar callback.
There is a multilistbox package somewhere - try the Tcl wiki to locate examples.

Capitalize first letter of sentence in CKeditor

I wish to capitalize the first letter of a sentence, on-the-fly, as the user types the text in a CKEditor content instance.
The strategy consists in catching each keystroke and try to replace it when necessary, that is for instance, when the inserted character follows a dot and a space. I'm fine with catching the event, but can't find a way to parse characters surrounding the caret position:
var instance = CKEDITOR.instances.htmlarea
instance.document.getBody().on('keyup', function(event) {
console.log(event);
// Would like to parse here from the event object...
event.data.preventDefault();
});
Any help would be much appreciated including a strategy alternative.
You should use keydown event (close to what you proposed):
var editor = CKEDITOR.instances.editor1;
editor.document.getBody().on('keydown', function(event) {
if (event.data.getKeystroke() === 65 /*a*/ && isFirstLetter()) {
// insert 'A' instead of 'a'
editor.insertText('A');
event.data.preventDefault();
}
});
Now - how should isFirstLetter() look like?
You have to start from editor.getSelection().getRanges() to get caret position.
You're interested only in the first range from the collection.
To extract text content from before the caret use small trick:
move start of the range to the beginning of document: range.setStartAt( editor.document.getBody(), CKEDITOR.POSITION_AFTER_START ),
use CKEDITOR.dom.walker to traverse through DOM tree in source order,
collect text nodes and find out what's before caret (is it /\. $/) - remember that you have to skip inline tags and stop on block tags - hint: return false from guard function to stop traversing.
Example of how you can use walker on range:
var range, walker, node;
range = editor.getSelection().getRanges()[0];
range.setStartAt(editor.document.getBody(), CKEDITOR.POSITION_AFTER_START);
walker = new CKEDITOR.dom.walker(range);
walker.guard = function(node) {
console.log(node);
};
while (node = walker.previous()) {}
And now few sad things.
We assumed that selection is empty when you type - that doesn't have to be true. When selection is not collapsed (empty) then you'll have to manually remove its content before calling insertText. You can use range#deleteContents to do this.
But this is not all - after deleting range's content you have to place caret in correct position - this isn't trivial. Basically you can use range#select (on the range after deleteContents), but in some cases it can place caret in incorrect place - like between paragraphs. Fixing this is... is not doable without deeeeeeeep knowledge about HTML+editables+insertions+other things :).
This solution is not complete - you have to handle paste event, deleting content (one can delete words from the start of sentence), etc, etc.
I guess there are couple of other problems I didn't even thought about :P.
So this approach isn't realistic. If you still want to implement this feature I think that you should set timer and by traversing DOM (you can use walker on range containing entire document, or recently typed text (hard to find out where it is)) find all sentences starting from lower letter and fix them.
This is what worked for me in Ckeditor 4.
var editor = CKEDITOR.instances.editor1;
editor.document.getBody().on('keydown', function(event) {
if (event.data.getKeystroke() >= 65 && event.data.getKeystroke()<=91 && encodeURI(this.getText())=="%0A" && this.getText().length==1 ) {
//uppercase the char
editor.insertText(String.fromCharCode(event.data.getKeystroke()));
event.data.preventDefault();
}
});

Issue with algorithm to shorten sentences

I have a webpage which displays multiple textual entries which have no restriction on their length. They get automatically cut if they are too long to avoid going to a new line. This is the PHP function to cut them:
function cutSentence($sentence, $maxlen = 16) {
$result = trim(substr($sentence, 0, $maxlen));
$resultarr = array(
'result' => $result,
'islong' => (strlen($sentence) > $maxlen) ? true : false
);
return $resultarr;
}
As you can see in the image below, the result is fine, but there are a few exceptions. A string containing multiple Ms (I have to account for those) will go to a newline.
Right now all strings get cut after just 16 characters, which is already very low and makes them hard to read.
I'd like to know if a way exists to make sure sentences which deserve more spaces get it and those which contain wide characters end up being cut at a lower number of characters (please do not suggest using the CSS property text-overflow: ellipsis because it's not widely supported and it won't allow me to make the "..." click-able to link to the complete entry, and I need this at all costs).
Thanks in advance.
You could use a fixed width font so all characters are equal in width. Or optionally get how many pixels wide every character is and add them together and remove the additional character wont the pixel length is over a certain amount.
If the style of your application isn't too important, you could simply use a font in the monospace family such as Courier.
Do it in Javascript rather than in PHP. Use the DOM property offsetWidth to get the width of the containing element. If it exceeds some maximum width, then truncate accordingly.
Code copied from How can I mimic text-overflow: ellipsis in Firefox? :
function addOverflowEllipsis( containerElement, maxWidth )
{
var contents = containerElement.innerHTML;
var pixelWidth = containerElement.offsetWidth;
if(pixelWidth > maxWidth)
{
contents = contents + "…"; // ellipsis character, not "..." but "…"
}
while(pixelWidth > maxWidth)
{
contents = contents.substring(0,(contents.length - 2)) + "…";
containerElement.innerHTML = contents;
pixelWidth = containerElement.offsetWidth;
}
}
Since you are asking for a web page then you can use CSS text-overflow to do that.
It seems to be supported enough, and for firefox there seems to be css workarounds or jquery workarounds...
Something like this:
span.ellipsis {
white-space:nowrap;
text-overflow:ellipsis;
overflow:hidden;
width:100%;
display:block;
}
If you fill more text than it fits it will add the three dots at the end.
Just cut the text if it is really too long so you don't waste html space.
More info here:
https://developer.mozilla.org/En/CSS/Text-overflow
Adding a 'see more' link at the end is easy enough, as appending another span with fixed width, containing the link to see more. text will be truncated with ellipsis before that.

Resources