Repository: qutebrowser/qutebrowser

Issue:
per-domain/URL-pattern default to passthrough
I would like to set the default input mode to `passthrough` for some websites, e.g. `*.gmail.com`, `email.*.edu` and `localhost:8787` (RStudio). Reading #27 and issues linked to it and the documentations, it seems I could edit `config.py` using the command `enter-mode passthrough`, but the documentation only shows how to change *settings* based on domain/URL, but not run commands. If this is an implemented feature, could we include a few lines in the official documentation (and here)?

**Version info (see `:version`)**:
```
qutebrowser v1.7.0
Git commit: 
Backend: QtWebEngine (Chromium 65.0.3325.230)

CPython: 3.7.4
Qt: 5.11.3
PyQt: 5.11.3

sip: 4.19.18
colorama: 0.3.7
pypeg2: 2.15
jinja2: 2.10.1
pygments: 2.3.1
yaml: 3.13
cssutils: no
attr: 18.2.0
PyQt5.QtWebEngineWidgets: yes
PyQt5.QtWebKitWidgets: yes
pdf.js: no
sqlite: 3.29.0
QtNetwork SSL: OpenSSL 1.1.1c  28 May 2019

Style: Qt5CTProxyStyle
Platform: Linux-4.19.0-5-amd64-x86_64-with-Debian-testing-buster, 64bit
Linux distribution: Debian GNU/Linux bullseye/sid (debian)
Frozen: False
Imported from /usr/lib/python3/dist-packages/qutebrowser
Using Python from /usr/bin/python3
Qt library executable path: /usr/lib/x86_64-linux-gnu/qt5/libexec, data path: /usr/share/qt5

Paths:
cache: /home/hyiltiz/.cache/qutebrowser
config: /home/hyiltiz/.config/qutebrowser
data: /home/hyiltiz/.local/share/qutebrowser
runtime: /run/user/1000/qutebrowser
system data: /usr/share/qutebrowser
```



Discussion:
Duplicate of https://github.com/qutebrowser/qutebrowser/issues/35
There is no such facility at the moment.
Great, thanks! I'll stop tweaking and hacking. 
I put this in the tabbedbrowser class.

```
if "localhost:888" in  str(tab.url()): 
            modeman.enter(self._win_id, usertypes.KeyMode.passthrough,reason='evil hack', only_if_normal=False)
```

Resolving patch:
diff --git a/qutebrowser/mainwindow/tabbedbrowser.py b/qutebrowser/mainwindow/tabbedbrowser.py
--- a/qutebrowser/mainwindow/tabbedbrowser.py
+++ b/qutebrowser/mainwindow/tabbedbrowser.py
@@ -223,6 +223,10 @@ def __init__(self, *, win_id, private, parent=None):
         # https://bugreports.qt.io/browse/QTBUG-65223
         self.cur_load_finished.connect(self._leave_modes_on_load)
 
+        # handle mode_override
+        self.current_tab_changed.connect(lambda tab: self._mode_override(tab.url()))
+        self.cur_url_changed.connect(self._mode_override)
+
         # This init is never used, it is immediately thrown away in the next
         # line.
         self.undo_stack: UndoStackType = collections.deque()
@@ -777,6 +781,23 @@ def _on_url_changed(self, tab, url):
         if not self.widget.page_title(idx):
             self.widget.set_page_title(idx, url.toDisplayString())
 
+    def _mode_override(self, url: QUrl) -> None:
+        """Override mode if url matches pattern.
+
+        Args:
+            url: The QUrl to match for
+        """
+        if not url.isValid():
+            return
+        mode = config.instance.get('input.mode_override', url=url)
+        if mode:
+            log.modes.debug(f"Mode change to {mode} triggered for url {url}")
+            modeman.enter(
+                self._win_id,
+                usertypes.KeyMode[mode],
+                reason='mode_override',
+            )
+
     @pyqtSlot(browsertab.AbstractTab)
     def _on_icon_changed(self, tab):
         """Set the icon of a tab.


Test patch:
diff --git a/tests/end2end/features/tabs.feature b/tests/end2end/features/tabs.feature
--- a/tests/end2end/features/tabs.feature
+++ b/tests/end2end/features/tabs.feature
@@ -1741,3 +1741,22 @@ Feature: Tab management
         And I run :undo
         And I run :message-info "Still alive!"
         Then the message "Still alive!" should be shown
+
+    Scenario: Passthrough mode override
+        When I run :set -u localhost:*/data/numbers/1.txt input.mode_override 'passthrough'
+        And I open data/numbers/1.txt
+        Then "Entering mode KeyMode.passthrough (reason: mode_override)" should be logged
+
+    Scenario: Insert mode override
+        When I run :set -u localhost:*/data/numbers/1.txt  input.mode_override 'insert'
+        And I open data/numbers/1.txt
+        Then "Entering mode KeyMode.insert (reason: mode_override)" should be logged
+
+    Scenario: Mode override on tab switch
+        When I run :set -u localhost:*/data/numbers/1.txt input.mode_override 'insert'
+        And I open data/numbers/1.txt
+        And I wait for "Entering mode KeyMode.insert (reason: mode_override)" in the log
+        And I run :fake-key -g <esc>
+        And I open data/numbers/2.txt in a new tab
+        And I run :tab-prev
+        Then "Entering mode KeyMode.insert (reason: mode_override)" should be logged