ergoemacs / ergoemacs-mode

ergoemacs-mode
ergoemacs.github.io/
GNU General Public License v3.0
293 stars 35 forks source link

set-key on specifik hook not working with ergoemacs #325

Closed codebold closed 9 years ago

codebold commented 9 years ago

The following code does not set the keybinding as expected if ergoemacs-mode is active on my emacs.

    (add-hook 'server-switch-hook
              (lambda ()
                [...]
                (global-set-key (kbd "C-w") 'server-edit))
    )

Is there a reason for this or a way to come around this issue? Thanks!

mattfidler commented 9 years ago

Yes. there are many ways to overcome this issue. One of the easiest is

    (add-hook 'server-switch-hook
              (let ((ergoemacs-is-user-defined-map-change-p t))
           (lambda ()
                [...]
                (global-set-key (kbd "C-w") 'server-edit))))

Another possibility is to make it a theme component. See https://groups.google.com/forum/#!topic/ergoemacs/iFOLu5tHHkY

mattfidler commented 9 years ago

It is actually a bug, by the way. I'm working on fixing it. I'm a bit swamped currently.

codebold commented 9 years ago

Thanks for your fast reply and your advice. However I was not able to get things going... Your proposal with (ergoemacs-is-user-defined-map-change-p t) didn't change the behavior and I'm also struggling with the theme-component approach. If i add the following code:

    (ergoemacs-theme-component ergoemacs-server ()
      "Emacs server"
      (when server-switch-hook
        (message "### server-switch-hook ###")
        (global-set-key global-map (kbd "C-w") 'server-edit)))

    (ergoemacs-require 'ergoemacs-server)

I can see the message in my Messages buffer, so the hook gets active, but the keybinding is still not applied...

I would really appreciate any further suggestions.

mattfidler commented 9 years ago

Thanks @codebold

You could do any of the following:

(global-set-key (kbd "C-w") 'server-edit)
(define-key global-map (kbd "C-w") 'server-edit)

Or by a theme component:

  (ergoemacs-theme-component ergoemacs-server ()
      "Emacs server"
     (global-set-key global-map (kbd "C-w") 'server-edit))

    (ergoemacs-require 'ergoemacs-server)

They typical ergoemacs-server command is bound globally. There is no keymap to modify for this command, so a global binding would work just fine.

I'm unsure what the purpose is of defining it only after the server is setup...Do you want to close the buffer after editing lt with emacs? If so, I think this may be what many users would like, and I should redefine close buffer to take care of server buffers...

mattfidler commented 9 years ago

This modification should allow Ctrl+w to close the server-editing session if it started, and then maintain the close buffer functionality elsewhere...

I don't use the server-edit component too much, if you decide to use this, let me know if it works.

codebold commented 9 years ago

You're right, the reason was to close server-editing session (http://www.emacswiki.org/emacs/EmacsClient#toc36). It would be great if ergoemacs would provide this functionality.

Unfortunately the recent changes did not work for me. I obtain ergoemacs from elpa, so the version on my machine is 'ergoemacs-mode-20141101.158'. I tried do add your changes manually to the file 'ergoemacs-functions.el', but with no effect (still receive "Buffer `xyz' still has clients; kill it? (y or n)" on close). So i cloned the repository and included ergoemacs directly. But, whenever i started emacsclients it was shutdown automatically and the terminal showed up again, so that i restored my previous configuration.

However, as the changes worked at your machine, its very likely that my configuration is somewhat demolished. So I will try it with a minimal configuration as soon as possible and report the outcome. Thanks for all your efforts!

mattfidler commented 9 years ago

@codebold I actually didn't try it out, I just thought it would work. I also think the other approach I just committed should work, but I work in windows so every time I try to stat a client it opens a new frame.

codebold commented 9 years ago

This time you nailed it! So far, it works like a charm. Many thanks again. Your work is greatly appreciated.

mattfidler commented 9 years ago

Great. Thank you for testing this for me.

mattfidler commented 9 years ago

I suggest you update again, othrewise killing the buffer may not work correctly.

codebold commented 9 years ago

Thanks!