-1

I opened a very large file by emacs, and I found it is too slow to go to the top of the buffer by hit M-<. And I also found that it is normal when I enter the command goto-line 1. So I want to override the default keybinding like:

(defun hao-goto-beginning-of-buffer-quickly ()
  "Go to beginning of the buffer quickly"
  (interactive)
  (goto-line 1)
  )
(global-set-key (kbd "M-<") 'hao-goto-beginning-of-buffer-quickly)

Then a weird situation happened. It is still very very slow when I hit M-<. But it is normal when I directly hit M-x hao-goto-beginning-of-buffer-quickly. I can not explain how this come? Do you ever come to this problem?

  • How big is the file? Emacs can become a bit slow when viewing really large files. Does this also happen when you run emacs as emacs -Q ? – Chakravarthy Raghunandan Oct 28 '16 at 5:37
  • around 20k line – ruanhao Oct 28 '16 at 5:37
  • 1
    That shouldn't cause any problems with jumping to beginning or end of file. Try opening the same file with emacs -Q and report if it's slow again – Chakravarthy Raghunandan Oct 28 '16 at 5:42
  • It is normal when -Q is added, but I need my configuration, and my question is why there is difference when global-set-key is used and not? – ruanhao Oct 28 '16 at 6:28
  • 1
    We know you need your configuration. The fact that the problem only occurs when you use your configuration, and not with emacs -Q, tells us that there is something in your configuration that causes the problem. The answer will be finding and fixing that problem, not using emacs -Q from now on. – Tyler Oct 28 '16 at 15:43
0

After I have checked init.el, I found that it is the problem of linum-mode.

I tried to disable global-linum-mode, and it goes fine.

So I wrote a shortcut:

(defun hao-goto-beginning-of-buffer-quickly ()
  "Go to beginning of the buffer quickly"
  (interactive)
  (global-linum-mode 0)
  (goto-line 1)
  (global-linum-mode 1)
  )
(global-set-key [(meta <)] 'hao-goto-beginning-of-buffer-quickly)
  • Please consider editing your question regarding how to properly (more efficiently) circumvent a problem with linum-mode, and include what you have tried. This answer should be deleted as it is inefficient at best. – lawlist Nov 8 '16 at 3:28
  • Maybe you can try using nlinum-mode instead? It claims to be (hopefully) faster. – npostavs Nov 8 '16 at 4:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.