keysnail icon indicating copy to clipboard operation
keysnail copied to clipboard

C-x b: switch-to-other-buffer

Open nochiel opened this issue 13 years ago • 5 comments

Is it possible to make Tanything behave in the same way that Buffer Switching in Emacs does? That is, upon pressing C-x b the most recently previously viewed buffer is highlighted in the tab (buffer) list that Tanything displays. This would allow faster and more convenient switching between buffers.

nochiel avatar Sep 23 '12 03:09 nochiel

man, i want this feature so bad!

math0ne avatar Oct 19 '12 22:10 math0ne

+1

I have got a naive implementation (a simple variable that keeps the last index) that works partially so not yet ready (because using anything else than the buffer switching will not propagate the change).

I'd like to implement this (or yet another plugin) using tab events to react to (because I believe listening to selection change, open or close tab events would suffice to implement it without touching any existing code).

But it seems the tab events are not native - https://developer.mozilla.org/en-US/docs/Web/Reference/Events (they are addons specific).

There is the addon-sdk which provides a high-level api to help with this: https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/tabs

But then I do not know how to deal with dependencies in keysnail.

Do you have any hints?

Cheers,

ardumont avatar Feb 14 '14 12:02 ardumont

Something along these lines (I do not say this code is fully correct as I cannot test it):


         // state of the index regarding currently selected and last selected
         var currentIndex = 0;
         var lastSelectedIndex = 0;

         function selectTab(event) {
             currentIndex = gBrowser.mTabContainer.selectedIndex;
         }

         function hideTab(event) {
             lastSelectedIndex = currentIndex;
         }

         function openTab (event) {
             currentIndex = gBrowser.mTabContainer.selectedIndex;
             if(currentIndex < lastSelectedIndex) lastSelectedIndex++;
             else f(lastSelectedIndex == currentIndex) lastSelectedIndex--;
         }

         function closeTab(event) {
             currentIndex = gBrowser.mTabContainer.selectedIndex;
             // if lastSelectedIndex is to the right of the tab we close, then this index is decremented by 1
             if(lastSelectedIndex > currentIndex+1) lastSelectedIndex--;
         }

         var container = gBrowser.tabContainer;
         container.addEventListener("TabOpen", openTab);
         container.addEventListener("TabClose", closeTab);
         container.addEventListener("TabSelect", selectTab);

Then modifying the Tanything.ks.js:

             function selectLastTabIndex() {
                 return lastSelectedIndex;
             }

             prompt.selector({
                 message             : "select tab: ",
                 initialIndex        : selectLastTabIndex(),
                 flags               : [ICON | IGNORE, 0, 0, IGNORE | HIDDEN],
                 collection          : currentCollection,
                 header              : ["title", "url"],
                 keymap              : pOptions.keymap,
                 actions             : tanythingAction,
                 supressRecoverFocus : true,
                 onFinish            : focusContent,
                 stylist             : function (args, n, current) {
                     if (current !== currentCollection)
                         return null;

                     let tab = args[3];
                     if (tab.pinned)
                         return pOptions.pinned_tab_style;
                     else
                         return null;
                 }
             });

This way, the rest of the existing code stays the same and the selection/closing/opening remains the same throughout all of firefox' use.

Cheers,

ardumont avatar Feb 14 '14 13:02 ardumont

The only way to deal with requirements in keysnail seems to be: https://github.com/mooz/keysnail/wiki/Writing-Plugins#wiki-require

ardumont avatar Feb 17 '14 18:02 ardumont

Anyone?

ardumont avatar Aug 03 '14 09:08 ardumont