Warm tip: This article is reproduced from serverfault.com, please click

Emacs on OSX breaks M-a and M-e in python-mode

发布于 2020-12-12 17:28:22

I've been using emacs for a while, and generally use it in Linux. I currently have emacs installed on OSX Catalina and M-a and M-e doesn't appear to work very well in python mode.

I'm going to try to illustrate with this bit of code, but if you've had this issue, I don't think it would require too much explanation:

L = [1, 2, 3, 4] #a

def double(x): #b
    return x * 2 #c

def fun(x): #d
    return [double(i) for i in x] #e

zz = fun(L) #f

print(zz) #g

If I start at the beginning of line #a, the M-e, I can only get to the beginning of lines #b and #d, and cannot go any further down the page. I would expect to be able to get to the ends of #c, #e, #f, and #g.

Using M-a causes similar issues. C-a and C-e work as expected.

I did remap option and command so they would be more what I'm used to from Linx world.

 ;; make MacOS sane
(setq mac-option-modifier 'control)
(setq mac-command-modifier 'meta)

This whole thing is annoying, searching pulls up no talk of this, and therefore no solutions. This problem only occurs with Python. Other languages I've tried seem to working as expected.

Questioner
dizzystar
Viewed
0
nega 2021-02-25 06:24:11

M-a and M-e are working as intended in python-mode.

In python-mode these keys are bound to python-nav-backward-block and python-nav-forward-block respectively. In your example, lines #a, #f, and #g do not start a block of python, and lines #c and #e are within python blocks. You can view what python-mode defines as a block here.

Behavior close to what you want can be found in python-nav-forward-statement and python-nav-backward-statement which move to the beginning of the next or previous statement respectively. By default, these functions are not bound to any keys.