Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set custom shortcuts #447

Closed
spiderbit opened this issue Oct 5, 2019 · 45 comments
Closed

How to set custom shortcuts #447

spiderbit opened this issue Oct 5, 2019 · 45 comments

Comments

@spiderbit
Copy link

I want to set the following keybindings:

(define-key :keymap my-keymap "r" #'history-forwards)
(define-key :keymap my-keymap "g" #'history-backwards)
(define-key :keymap my-keymap "u" #'set-url-current-buffer)
(define-key :keymap my-keymap "c" #'scroll-up)
(define-key :keymap my-keymap "t" #'scroll-down)
(define-key :keymap my-keymap "d" #'scroll-page-up)
(define-key :keymap my-keymap "s" #'scroll-page-down)

It's inspired by https://github.com/xahlee/xah-fly-keys Dvorak layout and what I currently use for my browsers. (vimium extension for firefox/chromium, vimb...)

@Ambrevar
Copy link
Member

Ambrevar commented Oct 5, 2019

Hmm... What's your question? :p
What you wrote is correct, then you need to actually use the keymap in a mode, like this:

(define-mode my-mode ()
  "Dummy mode for the custom key bindings in `*my-keymap*'."
  ((keymap-schemes :initform (list :emacs-map *my-keymap*
                                   :vi-normal *my-keymap*))))

(defun my-buffer-defaults (buffer)
  (dolist (mode '(proxy-mode my-mode)) ;; <= Any mode that you want by default!
    (pushnew mode (default-modes buffer))))

(defun my-interface-defaults ()
  (hooks:add-to-hook (hooks:object-hook *interface* 'buffer-make-hook)
                     #'my-buffer-defaults))

Hope that helps!

@spiderbit
Copy link
Author

spiderbit commented Oct 5, 2019

This line:
(define-key :keymap my-keymap "r" #'history-forwards)

raised the error:

The variable NEXT::MY-KEYMAP is unbound.

is there some (make-keymap) ? If yes, it would be good to add that to the documentation. Or did I miss something else?

@Ambrevar
Copy link
Member

Ambrevar commented Oct 5, 2019 via email

@spiderbit
Copy link
Author

spiderbit commented Oct 5, 2019

Well thanks now it don't throws a error but it doesn't do what it supposed to do, none of the shortcuts works.

And it doesn't recognize the 2 history functions even in the console they are a choice.

The function NEXT::HISTORY-FORWARDS is undefined.

Do I have to write wrapper functions around that functions which is what I see in the extensions.org documentation file

Ideally you could post a minimal init file that works on your side? with that shortcuts? Before we go another 5 times forth and back?

@tviti
Copy link
Contributor

tviti commented Oct 6, 2019

I get the same error as you when I try to add the same keybinding. Looks like history-forwards is defined in the web-mode package, and isn't actually visible from :next (I guess not till the buffer gets created, and web-mode is activated)?

Try this:

(define-key :keymap my-keymap "r" #'next/web-mode:history-forwards)

@Ambrevar
Copy link
Member

Ambrevar commented Oct 6, 2019 via email

@spiderbit
Copy link
Author

spiderbit commented Oct 6, 2019

Well now history function works btw here on github always the star "*" get suppressed around my-keymap apperently sucks when you poste code and it hides parts of it, don't get how that can happen...

But the other commands seem to work, too. But history is buggy:

  1. after opening a url back brings me not back to the start page. Even if I click on a link on the startpage back don't brings me back. So the startpage is not in the history can be seen as feature not sure feels a bit odd to me.
  2. very strange behaviour that is different on differenent websites: so if I go to google or github and I press history back it reloads the site and does the resizing I set up in the hook (hidpi) which is odd if it has only 1 site in the history forward and backward should not reload the page it should just do nothing right?
    But when I open heise.de (a german IT news site) it does ignore history back/forth and not reloads the site?

Should I open a new bug for that? Is that maybe some internet forwarding this sites do and the browser registers as 2 different websites when in fact it's the same?

@Ambrevar
Copy link
Member

Ambrevar commented Oct 6, 2019 via email

@spiderbit
Copy link
Author

spiderbit commented Oct 6, 2019

K I checked again the handling of the star/multiply sign.

In my original post I posted the source as normal text not as source therefor it removed the * around the my-keymap strings when I saw your code and that I had to add the * around it to make it work:

(define-key :keymap my-keymap "r" #'next/web-mode:history-forwards)

I assumed you also did have the * around the my-keymap and it got stripped from it, if you mark it as source it don't read it as markup, you just forgot them.
So that is fine.

About the heise.de site besides the point that the startpage is not in the history it works fine it's just the google/github sites that don't work correctly so it makes no sense to report a bug because 1 site works correct I think?

It's just odd to me why it site specific works differently... The history is a bit rough but it's not very crucial to me at the point I need "darkmode" before I can use the browser productive here and you said that that this part is just rewritten. Maybe it's better to wait 1 release before I write a bugreport on that part?

I mean if I go on heise.de press a article, I can go back to the main page over history-back but forward then reloads the main page... that seems to me not very hard to reproduce right? :-)

@Ambrevar
Copy link
Member

Ambrevar commented Oct 6, 2019 via email

@azzamsa
Copy link

azzamsa commented Dec 5, 2019

Is this the correct MWE of overriding the default keybinding?

(in-package :next)

(defvar *my-keymap* (make-keymap)
  "My keymap.")

(define-mode my-mode ()
  "Dummy mode for the custom key bindings in `*my-keymap*'."
  ((keymap-schemes :initform (list :emacs-map *my-keymap*
                                   :vi-normal *my-keymap*))))

(defun my-buffer-defaults (buffer)
  (dolist (mode '(proxy-mode my-mode)) ;; <= Any mode that you want by default!
    (pushnew mode (default-modes buffer))))

(defun my-interface-defaults ()
  (hooks:add-to-hook (hooks:object-hook *interface* 'buffer-make-hook)
                     #'my-buffer-defaults))

(define-key :keymap *my-keymap* "s-m" #'switch-buffer)
  1. start next
  2. do M-x my-mode
  3. press s-m (windows + m). But nothing happened. I've tried to use different key but didn't work either.

Did I miss something?

@Ambrevar
Copy link
Member

Ambrevar commented Dec 5, 2019 via email

@azzamsa
Copy link

azzamsa commented Dec 6, 2019

You are not installing the new interface defaults ;) You just miss this line:

Where to add that line? is it here?

+ (hooks:add-to-hook '*after-init-hook* #'my-interface-defaults)
(define-key :keymap *my-keymap* "C-x m" #'switch-buffer)

If yes, it didn't manage to work either. I've tried the key to "C-x m", "s-m", "m". Am I missing something?

@Ambrevar
Copy link
Member

Ambrevar commented Dec 6, 2019 via email

@azzamsa
Copy link

azzamsa commented Dec 6, 2019

Maybe declare a list of known keymap schemes globally?

Your latest snippets works for me. So you changed (in-package :next-user) and (list :emacs *my-keymap*.

Thank you :)

@Ambrevar
Copy link
Member

Ambrevar commented Dec 6, 2019 via email

@azzamsa
Copy link

azzamsa commented Dec 6, 2019

Okay thanks, everything sets. I am unable to use super key, and want to open new issue, turns out it was S on next (in emacs it's s).

Thank you.

@jmercouris
Copy link
Member

If the problem is solved, may we close this issue?

@azzamsa
Copy link

azzamsa commented Dec 6, 2019

@jmercouris I am not the author, :)

@Ambrevar
Copy link
Member

I think we can close this now. Feel free to reopen if there is anything else.

@dalanicolai
Copy link

dalanicolai commented May 9, 2020

Hi! I am trying to set custom keybindings for vi-mode. However the code in the documentation is not clear to me/does not work. For example if I use the init file as given in this comment above then I get the following error message:

Next version 1.5.0-73ab116f
Loading Lisp file #P"/home/dalanicolai/.config/next/init.lisp"...
While evaluating the form starting at line 3, column 0
  of #P"/home/dalanicolai/.config/next/init.lisp":
Unhandled SIMPLE-ERROR in thread #<SB-THREAD:THREAD "main thread" RUNNING
                                    {10006F05B3}>:
  Error: we could not load the init file:
invalid number of arguments: 0

Backtrace for: #<SB-THREAD:THREAD "main thread" RUNNING {10006F05B3}>
0: (SB-DEBUG::DEBUGGER-DISABLED-HOOK #<SIMPLE-ERROR "~a:~&~a" {1006389C63}> #<unused argument> :QUIT T)
1: (SB-DEBUG::RUN-HOOK *INVOKE-DEBUGGER-HOOK* #<SIMPLE-ERROR "~a:~&~a" {1006389C63}>)
2: (INVOKE-DEBUGGER #<SIMPLE-ERROR "~a:~&~a" {1006389C63}>)
3: (UIOP/IMAGE:HANDLE-FATAL-CONDITION #<SIMPLE-ERROR "~a:~&~a" {1006389C63}>)
4: (SB-KERNEL::%SIGNAL #<SIMPLE-ERROR "~a:~&~a" {1006389C63}>)
5: (ERROR "~a:~&~a" "Error: we could not load the init file" #<SB-INT:SIMPLE-PROGRAM-ERROR "invalid number of arguments: ~S" {1006389813}>)
6: (NEXT::LOAD-LISP #P"/home/dalanicolai/.config/next/init.lisp" :INTERACTIVE T)
7: (NEXT:START :URLS NIL :INIT-FILE NIL)
8: ((LAMBDA NIL :IN UIOP/IMAGE:RESTORE-IMAGE))
9: (UIOP/IMAGE:CALL-WITH-FATAL-CONDITION-HANDLER #<CLOSURE (LAMBDA NIL :IN UIOP/IMAGE:RESTORE-IMAGE) {100621BE9B}>)
10: ((FLET SB-UNIX::BODY :IN SAVE-LISP-AND-DIE))
11: ((FLET "WITHOUT-INTERRUPTS-BODY-14" :IN SAVE-LISP-AND-DIE))
12: ((LABELS SB-IMPL::RESTART-LISP :IN SAVE-LISP-AND-DIE))

unhandled condition in --disable-debugger mode, quitting

line 3 is the defvar form

Is this a bug (it means the make-keymap requires an argument)? Thanks for your help... (and the beautiful browser!)

@Ambrevar
Copy link
Member

Ambrevar commented May 9, 2020

Thank you for reporting, there was a documentation bug indeed!

Fixed in commit 14bf6c4.

  • make-keymap takes a name (a string) as argument.
  • I recommend you use define-configuration to simplify the configuration.

Minimal example:

(define-mode my-mode ()
  "Dummy mode for the custom key bindings in `*my-keymap*'."
  ((keymap-scheme :initform
                  (define-scheme "my-scheme"
                    scheme:cua
                    (list
                     "C-f" 'history-forwards
                     "C-b" 'history-backwards)

                    scheme:emacs
                    (list ...)))))

(define-configuration buffer
  ((default-modes (append '(my-mode) %slot-default))))

@dalanicolai
Copy link

dalanicolai commented May 11, 2020

Thanks for looking into it. Unfortunately I do not understand much yet of common-lisp or the next documentation.

When I try the new code from the documentation, for example the following part

(defvar *my-keymap* (make-keymap "my-map")
(define-key *my-keymap*
  "C-f" 'history-forwards
  "C-b" 'history-backwards)

(define-mode my-mode ()
  "Dummy mode for the custom key bindings in `*my-keymap*'."
  ((keymap-scheme :initform (keymap:make-scheme
                             scheme:emacs *my-keymap*
                             scheme:vi-normal *my-keymap*))))

(define-configuration buffer
  ((default-modes (append '(my-mode) %slot-default))))

then I still get an error:

Next version 1.5.0-73ab116f
Loading Lisp file #P"/home/dalanicolai/.config/next/init.lisp"...
Unhandled SIMPLE-ERROR in thread #<SB-THREAD:THREAD "main thread" RUNNING
                                    {10006F05B3}>:
  Error: we could not load the init file:
READ error during LOAD:

  end of file on #<SB-INT:FORM-TRACKING-STREAM for "file /home/dalanicolai/.config/next/init.lisp" {1006373313}>

  (in form starting at line: 1, column: 0, position: 0)

Backtrace for: #<SB-THREAD:THREAD "main thread" RUNNING {10006F05B3}>
0: (SB-DEBUG::DEBUGGER-DISABLED-HOOK #<SIMPLE-ERROR "~a:~&~a" {1006376523}> #<unused argument> :QUIT T)
1: (SB-DEBUG::RUN-HOOK *INVOKE-DEBUGGER-HOOK* #<SIMPLE-ERROR "~a:~&~a" {1006376523}>)
2: (INVOKE-DEBUGGER #<SIMPLE-ERROR "~a:~&~a" {1006376523}>)
3: (UIOP/IMAGE:HANDLE-FATAL-CONDITION #<SIMPLE-ERROR "~a:~&~a" {1006376523}>)
4: (SB-KERNEL::%SIGNAL #<SIMPLE-ERROR "~a:~&~a" {1006376523}>)
5: (ERROR "~a:~&~a" "Error: we could not load the init file" #<SB-C::INPUT-ERROR-IN-LOAD {1006376353}>)
6: (NEXT::LOAD-LISP #P"/home/dalanicolai/.config/next/init.lisp" :INTERACTIVE T)
7: (NEXT:START :URLS NIL :INIT-FILE NIL)
8: ((LAMBDA NIL :IN UIOP/IMAGE:RESTORE-IMAGE))
9: (UIOP/IMAGE:CALL-WITH-FATAL-CONDITION-HANDLER #<CLOSURE (LAMBDA NIL :IN UIOP/IMAGE:RESTORE-IMAGE) {100621BE9B}>)
10: ((FLET SB-UNIX::BODY :IN SAVE-LISP-AND-DIE))
11: ((FLET "WITHOUT-INTERRUPTS-BODY-14" :IN SAVE-LISP-AND-DIE))
12: ((LABELS SB-IMPL::RESTART-LISP :IN SAVE-LISP-AND-DIE))

unhandled condition in --disable-debugger mode, quitting

I guess maybe the defvar form misses a closing parenthesis, but when I add the parenthesis then I get another error:

Next version 1.5.0-73ab116f
Loading Lisp file #P"/home/dalanicolai/.config/next/init.lisp"...

; file: /home/dalanicolai/.config/next/init.lisp
; in: DEFVAR *MY-KEYMAP*
;     (MAKE-KEYMAP "my-map")
; 
; caught STYLE-WARNING:
;   undefined function: MAKE-KEYMAP
; 
; compilation unit finished
;   Undefined function:
;     MAKE-KEYMAP
;   caught 1 STYLE-WARNING condition
While evaluating the form starting at line 1, column 0
  of #P"/home/dalanicolai/.config/next/init.lisp":
Unhandled SIMPLE-ERROR in thread #<SB-THREAD:THREAD "main thread" RUNNING
                                    {10006F05B3}>:
  Error: we could not load the init file:
The function COMMON-LISP-USER::MAKE-KEYMAP is undefined.

Backtrace for: #<SB-THREAD:THREAD "main thread" RUNNING {10006F05B3}>
0: (SB-DEBUG::DEBUGGER-DISABLED-HOOK #<SIMPLE-ERROR "~a:~&~a" {100638E853}> #<unused argument> :QUIT T)
1: (SB-DEBUG::RUN-HOOK *INVOKE-DEBUGGER-HOOK* #<SIMPLE-ERROR "~a:~&~a" {100638E853}>)
2: (INVOKE-DEBUGGER #<SIMPLE-ERROR "~a:~&~a" {100638E853}>)
3: (UIOP/IMAGE:HANDLE-FATAL-CONDITION #<SIMPLE-ERROR "~a:~&~a" {100638E853}>)
4: (SB-KERNEL::%SIGNAL #<SIMPLE-ERROR "~a:~&~a" {100638E853}>)
5: (ERROR "~a:~&~a" "Error: we could not load the init file" #<UNDEFINED-FUNCTION MAKE-KEYMAP {100638E313}>)
6: (NEXT::LOAD-LISP #P"/home/dalanicolai/.config/next/init.lisp" :INTERACTIVE T)
7: (NEXT:START :URLS NIL :INIT-FILE NIL)
8: ((LAMBDA NIL :IN UIOP/IMAGE:RESTORE-IMAGE))
9: (UIOP/IMAGE:CALL-WITH-FATAL-CONDITION-HANDLER #<CLOSURE (LAMBDA NIL :IN UIOP/IMAGE:RESTORE-IMAGE) {100621BE9B}>)
10: ((FLET SB-UNIX::BODY :IN SAVE-LISP-AND-DIE))
11: ((FLET "WITHOUT-INTERRUPTS-BODY-14" :IN SAVE-LISP-AND-DIE))
12: ((LABELS SB-IMPL::RESTART-LISP :IN SAVE-LISP-AND-DIE))

unhandled condition in --disable-debugger mode, quitting

Unfortunately as I do not know common-lisp (nor CLOS) yet, and because I don't know further introspection options yet, I can not provide much more/useful information...

@jmercouris
Copy link
Member

Can you please post the entirety of your init file so that we may better assist you? Thanks!

@jmercouris
Copy link
Member

Also you are correct, it should be:

(defvar *my-keymap* (make-keymap "my-map"))

@dalanicolai
Copy link

Hi thanks for looking into it. Because things were not working I removed all other code from the init file so that it contained the code I posted in my last comment above exclusively (where because of your last comment I now added that extra parenthesis). So the following is currently the full code in my init file:

(defvar *my-keymap* (make-keymap "my-map"))
  (define-key *my-keymap*
    "C-f" 'history-forwards
    "C-b" 'history-backwards)

  (define-mode my-mode ()
    "Dummy mode for the custom key bindings in `*my-keymap*'."
    ((keymap-scheme :initform (keymap:make-scheme
                               scheme:emacs *my-keymap*
                               scheme:vi-normal *my-keymap*))))

  (define-configuration buffer
      ((default-modes (append '(my-mode) %slot-default))))

When I try to run next then I get the error message (the second one because now I added the parenthesis) that I posted in my last comment above

@Ambrevar
Copy link
Member

Ambrevar commented May 13, 2020 via email

@azzamsa
Copy link

azzamsa commented May 21, 2020

@Ambrevar This snippet doesn't work anymore.

I am getting this error:

$ ./next
Next version 1.5.0
Loading configuration from #P"/home/john/.config/next/init.lisp"...

Error: we could not load the init file
READ error during LOAD:

  Package HOOKS does not exist.

    Line: 36, Column: 20

    Stream: #<SB-INT:FORM-TRACKING-STREAM for "file /home/john/.config/next/init.lisp" {1004C585F3}>

trying the snippet from the docs also didn't work:

$ ./next
Next version 1.5.0
Loading configuration from #P"/home/john/.config/next/init.lisp"...
While evaluating the form starting at line 55, column 0
  of #P"/home/john/.config/next/init.lisp":
Error: we could not load the init file
invalid number of arguments: 1

Any breaking changes or am I missing something?

@Ambrevar
Copy link
Member

This topic is heavily outdated. In the newest Next, run the tutorial command. At the end you'll find a bunch of configuration snippets.

@Ambrevar
Copy link
Member

Let me know if you need help with a particular config.

@dalanicolai
Copy link

@Ambrevar I wanted to try a few days ago with the newest version, but when I click the Download link in the git README then I got a "502 Bad Gateway" error, I assumed it would get fixed and today I wanted to try again but I still get the same error, despite #744 was closed yesterday because the Download page was/should be available again.

Also as recommended in #744, I tried to build from source but I get a build error. I saved the output of the make process in the following file:
make_all.log
Unfortunately I do not understand this log well yet. It seems to me that all the variables/flags are set correctly. (The command make next also errors)

@azzamsa
Copy link

azzamsa commented May 21, 2020

This topic is heavily outdated. In the newest Next, run the tutorial command. At the end you'll find a bunch of configuration snippets.

@Ambrevar Thanks for the tip. Unfortunately tutorial command only availiable at 2.0. I still having problem running next with guix from source, Any hints?

@azzamsa
Copy link

azzamsa commented May 21, 2020

I've tried to compile the tutorial to to html manually using cl-markup, this is the result.

image

I think we have typo in (defvar *my-keymap*...

I peak your config and covert mine to:

(in-package :next-user)

(defvar *my-keymap* (make-keymap "my-map")
  "Keymap for `my-mode'.")

(define-key *my-keymap*
  "C-f" 'history-forwards
  "C-b" 'history-backwards)

(define-mode my-mode ()
  "Dummy mode for the custom key bindings in `*my-keymap*'."
  ((keymap-scheme :initform (keymap:make-scheme
                             scheme:cua *my-keymap*
                             scheme:emacs *my-keymap*
                             scheme:vi-normal *my-keymap*))))

(define-configuration buffer
  ((default-modes (append '(my-mode) %slot-default))))

but still have the same error:

$ ./next
Next version 1.5.0
Loading configuration from #P"/home/user/.config/next/init.lisp"...
While evaluating the form starting at line 3, column 0
  of #P"/home/user/.config/next/init.lisp":
Error: we could not load the init file
invalid number of arguments: 1

@Ambrevar
Copy link
Member

Ambrevar commented May 22, 2020 via email

@Ambrevar
Copy link
Member

Ambrevar commented May 22, 2020 via email

@dalanicolai
Copy link

@Ambrevar I indeed meant that download link which was not working when I created my last comment (and also the previous time), but it is working now here too.

Actually to get build instructions for next, I tried to access the developer manual page but that also gave error 502 at that time. Therefore I followed the instructions in the INSTALL file in the repo. However, I had two copies of the repo, one in my ~/git directory and another one in my ~/common-lisp directory and I had forgotten about the latter one. So I was following the instruction in the repo in my ~/git directory. Now that I could access the Developer Manual again, I found that I should build from the repo in my ~/common-lisp directory. So that solves the issue of my last comment.
But I suggest to also mention in the INSTALL file that the build should be done from a repo within the ~/common-lisp directory.

However, some build error remains even after pulling the latest version of the repo. So as you requested I will open a new issue for that.

@Ambrevar
Copy link
Member

Ambrevar commented May 23, 2020 via email

@dalanicolai
Copy link

dalanicolai commented May 23, 2020 via email

@Ambrevar
Copy link
Member

Ambrevar commented May 25, 2020 via email

@azzamsa
Copy link

azzamsa commented May 25, 2020

@Ambrevar I've successfully installed latest next with guix. However the customizing keybinding example in docs doesn't work. I've convert my old config but it also doesn't work:

(in-package :next-user)

(defvar *my-keymap* (make-keymap "my-map"))

(define-key *my-keymap*
  "C-m" 'switch-buffer)

(define-mode my-mode ()
  "Dummy mode for the custom key bindings in `*my-keymap*'."
  ((keymap-scheme :initform (keymap:make-scheme
                             scheme:emacs *my-keymap*
                             scheme:vi-normal *my-keymap*))))

(define-configuration buffer
  ((default-modes (append '(my-mode) %slot-default))))

And I can't do M-x to call any function.

@Ambrevar
Copy link
Member

Ambrevar commented May 26, 2020 via email

@azzamsa
Copy link

azzamsa commented May 26, 2020

this works for me

(in-package :next-user)

(defvar *my-keymap* (make-keymap "my-map"))

(define-key *my-keymap*
  "S-m" 'switch-buffer)

(define-mode my-mode ()
  "Dummy mode for the custom key bindings in `*my-keymap*'."
  ((keymap-scheme :initform (keymap:make-scheme
                             scheme:cua *my-keymap*
                             scheme:emacs *my-keymap*
                             scheme:vi-normal *my-keymap*))))


(define-configuration buffer
  ((default-modes (append '(my-mode emacs-mode) %slot-default))))

@Ambrevar
Copy link
Member

Ambrevar commented May 26, 2020 via email

@azzamsa
Copy link

azzamsa commented May 27, 2020

Would you like to suggest an improvement to the documentation?

Sure!

@Ambrevar
Copy link
Member

Ambrevar commented May 27, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants