Bind rope-auto-import to a keyboard shortcut in emacs - emacs

The way I know to auto-import using rope is to move my cursor to the name I want to import and do M-x rope-auto-import. I'd like to bind rope-auto-import to a keyboard shortcut to make this faster.

Figured it out:
Add the following line to my .emacs file:
(global-set-key (kbd "C-c a") 'rope-auto-import)
M-x load-file RET ~/.emacs RET

Related

Why Emacs adds new lines at the end of the file while pressing the down arrow?

How is it possible to avoid emacs to add new blank lines while pressing the down arrow at the end of the file?
Also, if it can help, I had to re-customize
(global-set-key (kbd "C-<up>") 'backward-paragraph)
(global-set-key (kbd "C-<down>") 'forward-paragraph)
because this default behavior did not work.
I have GNU Emacs 24.3.1.
Just set the next-line-add-newlines to a false value:
(setq next-line-add-newlines nil)
(or remove the line that sets it to t).

Bind RET to send scheme code in emacs

I want to set up my .emacs so that when I am in my *scheme* buffer I can bind RET to C-x C-e (because I use C-j for newlines). I get to the scheme buffer like this:
M-x load-library RET xscheme RET note - how can I automate that step?
M-x run-scheme
Here's what I tried, it doesn't work:
(eval-after-load 'xscheme
'(define-key scheme-mode-map
(kbd "RET")
'advertised-xscheme-send-previous-expression))
Seems strange to bind it like that.
Here's how it's done in Emacs 24.4:
(eval-after-load 'cmuscheme
(define-key inferior-scheme-mode-map
(kbd "RET") 'scheme-send-last-sexp))

Key binding to reload .emacs after changing it?

As a novice Emacs user (I'm about 3 months into what's probably a lifelong journey), I make changes to my .emacs file pretty regularly. It would be handy to have a global key binding to reload .emacs rather than go through the incredibly laborious process of M-x load-file (delete a long string if I'm deep into some directory) ~/.emacs <RET>. I've attempted a solution, but
;; reload .emacs when C-c <f12> is pressed
(defun reload-dotemacs ()
(load-file "~/.emacs"))
(global-set-key (kbd "C-c <f12>")
(lambda() (interactive) 'reload-dotemacs))
doesn't seem to work. Basically, when I enter the key combination, nothing happens, whereas trying M-x load-file ~/.emacs makes things happen (e.g. I see my yasnippet files reload).
For the record, C-c <f12> doesn't seem to be bound to anything else.
Fix for your code
(defun reload-dotemacs ()
(interactive)
(load-file "~/.emacs"))
(global-set-key (kbd "C-c <f12>") 'reload-dotemacs)
You do not need it 1
You do not need to remove the default string when you do M-x load-file RET - just type ~/.emacs.el RET and it will work.
You do not need it 2
Do not reload the init file, just evaluate the new code.
Type C-h m and C-h b in the .emacs.el buffer and you will see the useful keybindings (after searching for eval):
C-c C-b eval-current-buffer
C-c C-r eval-region
C-M-x eval-defun
C-j eval-print-last-sexp
C-x C-e eval-last-sexp

Launch py-shell command in another emacs window

When using python-mode in Emacs, I first split the screen via C-x 3.
I'd like to be able do C-c ! to launch py-shell in the other window, not in the window currently active. How can I configure Emacs to do that without having to switch windows with C-x o before launching the shell?
I'm using Emacs 24.3.1, and I've got all my configuration files in ~/.emacs.d.
I just installed the python-mode package using package-install with the Marmalade repository, and I haven't yet edited any .el file related to python-mode.
As #BleedingFingers says you can simply use a macro and bind that to a key. It's up to you whether or not you want to re-use the C-c ! binding for the macro or bind it to a different key.
Here's how to proceed should you decide to go with the macro option, starting with Emacs showing only a single window:
Define macro
F3
C-x 3
C-x o
M-x py-shell RET
C-x o
F4
Assign name to macro
M-x name-last-kbd-macro RET py-shell-other-window RET
You can replace py-shell-other-window with whatever name you would like to use for the macro.
Add macro to your configuration
Open your configuration file, move point (cursor) to an empty line and do
M-x insert-kbd-macro RET
This will insert the macro definition into your configuration file.
Bind macro to key
Add the following code to your configuration file to bind the macro to a key in python-mode:
(require 'python-mode) ; Make sure python-mode-map is available
; for modification
(define-key python-mode-map (kbd "C-c !") nil) ; Unset default binding
; for C-c !
; (not necessary if you choose an
; unused binding)
(define-key python-mode-map (kbd "C-c !") 'py-shell-other-window) ; Bind macro to C-c !
Turn key binding on
Mark the lines added in the previous step and run M-x eval-region RET, or simply restart Emacs.
Celebrate :)
Advice lets you redefine code in other libraries on-the-fly.
(defadvice py-shell (around auto-split activate)
(split-window-right)
(other-window)
,ad-do-it
(other-window))
Variations apply.

How to define a global-set-key for M-x color-theme-<TAB> RET

I haven't been able to locate any examples of how to use global-set-key in conjunction with M-x color-theme-<TAB> RET. I've tried several variations, but to no avail. Is it possible to insert a tab at the end of color-theme?
(global-set-key "\C-ct" 'color-theme<TAB><RET>)
This keyboard shortcut pulls up a similar screen that can be clicked with a mouse.
(global-set-key (kbd "<f5>") 'color-theme-select)
On a related note:
Aquamacs 2.4 disables the color-theme menubar entry under tools. So if anyone wants to enable it, then insert this into the Preferences.el or init.el (if you have one):
(easy-menu-add-item nil color-theme-entry-path "--")
(easy-menu-add-item nil color-theme-entry-path
["Color Themes" color-theme-select t])
Aquamacs 2.4 already has this somewhere else in its initialization:
(require 'easymenu)
Alternatively, the user can remove the ;; from /Applications/Aquamacs.app/Contents/Resources/lisp/aquamacs/color-theme.el at lines 513 to 516.