Tuesday 25 September 2018

firefox - How to open previous/next page in new tab in Pentadactyl?


If pressing H and L brings you to the previous and next pages, respectively (Alt+Left/Right on vanilla Firefox), what's the key for opening the previous/next page in a new tab?


The functionality I'm trying to achieve is like middle-clicking the left and right arrows beside the address bar, preferably without needing to access the history (i.e. for Private Browsing Mode) If possible, is there some way to do this for the other items in the :ju (jump) list?


Note (2015/05/15): I switched to Vimperator some time ago and am still lacking the "open next/previous page in new tab", but the solution marked below works perfectly when I turned Pentadactyl on again.


Note (2015/05/17): pyrocrasty added a Vimperator version to the solution which also works great.



Answer







There's actually a key Ctrl +T which is meant to execute the next mapping in a new tab. However, it doesn't work for me at all. I don't know why.


There's also the ex command tab which does the same thing for the next ex command. However, it doesn't seem to work properly with history commands. It duplicates the tab but doesn't go back.





You can achieve this by combining two commands:




  1. tabduplicate (or tabdu) duplicates the current tab, preserving history.


    You can bind it to a key by adding a line like this to your .pentadactylrc file:


        map -g user -ex C :tabduplicate


  2. H and L are back and forward, as you mentioned.


    So if you use the example binding above, you can use CH to open the previous page in a new tab.




note: Position of new tabs.


One important caveat is that, depending on your settings, this method may open the new tab in a different position to right-clicking the history buttons. The command C, as defined above, will open the tab at the end of the tab bar rather than after the current tab.


If you prefer the tabs to open next to the current one, you can use an extension to open all new tabs after the current tab. Tab Mix Plus is a popular choice.





I've had trouble trying to get a single command to duplicate a tab and then move forward or back in it. However, it's easy to duplicate a tab in the background and then move forward or back in the original tab.


This has mostly the same effect except that the positions of the two tabs are switched: you go back in history where you are and the tab in its original state is left wherever new tabs open. You'll probably only want to consider this if you're using an extension to make all new tabs open next to the current one.


    map -g user -ex [t :execute "tabduplicate! | back"
map -g user -ex ]t :execute "tabduplicate! | forward"

Then you can open the previous page in a new tab with [t (you could use a single-letter keybinding if you have one available).





I've got this working now, with a Javascript command. The problem with my earlier naive attempts was that they tried to go back in history before the history was available. After some research, I've solved the problem with an event listener.


The code is in this gist (update: vimperator version). Either include it in your .pentadactylrc file directly, or save it separately (preferably in .pentadactyl directory) and source it from .pentadactylrc. eg.


:source "~/.pentadactyl/backt-forwardt.penta"

Then you can use gh and gl to achieve the same results as middle-clicking the back/forward buttons.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...