benma / visual-regexp.el

A regexp/replace command for Emacs with interactive visual feedback
392 stars 28 forks source link

(require 'visual-regexp) messes with key bindings to C-a #34

Closed Rovanion closed 8 years ago

Rovanion commented 8 years ago

I've just debugged the strangest issue with my emacs init files of which a part looks like:

(require 'visual-regexp)
(define-key global-map (kbd "C-c r") 'vr/replace)
(define-key global-map (kbd "M-%") 'vr/query-replace)
(define-key global-map (kbd "C-c q") 'vr/query-replace)

(defun smart-line-beginning ()
  (interactive)
  (let ((pt (point)))
    (beginning-of-line-text)
    (when (eq pt (point))
      (beginning-of-line))))

(define-key prog-mode-map (kbd "RET") 'newline-and-indent)
(define-key prog-mode-map (kbd "C-j") 'newline)
(define-key prog-mode-map (kbd "C-a") 'smart-line-beginning)

As it turns out the above code doesn't work in the sense that C-a get rebound to move-beginning-of-line at some point. But if I move (require 'visual-regexp) below the key binding like

(defun smart-line-beginning ()
  (interactive)
  (let ((pt (point)))
    (beginning-of-line-text)
    (when (eq pt (point))
      (beginning-of-line))))

(define-key prog-mode-map (kbd "RET") 'newline-and-indent)
(define-key prog-mode-map (kbd "C-j") 'newline)
(define-key prog-mode-map (kbd "C-a") 'smart-line-beginning)

(require 'visual-regexp)
(define-key global-map (kbd "C-c r") 'vr/replace)
(define-key global-map (kbd "M-%") 'vr/query-replace)
(define-key global-map (kbd "C-c q") 'vr/query-replace)

C-a stays bound to smart-line-beginning as it should.

I have absolutely no idea why this is, and I know that it doesn't effect the binding of RET and C-j which are mentioned above, but I've been able to replicate this using only the above code as my init file.

benma commented 8 years ago

As it turns out the above code doesn't work in the sense that C-a get rebound to move-beginning-of-line at some point.

When does that happen exactly? When I use this init file, C-a stays bound as expected.

Which Emacs version are you using?

Rovanion commented 8 years ago

I'm running GNU Emacs 24.5.1 on Ubuntu 16.04.

But it seems like I can't reproduce the issue on my end now either. So I've probably done completely goofed for which I apologise.

I'll instead take this time out of your day to remind you that visual-regexp is absolutely fantastic and it makes me smile every time I use it!

benma commented 8 years ago

That is very kind, thank you :smile: