I have switched to using emacs-ess for my R code development and it is working great. I would like to be able to write some small R code I am using for debugging my R script into the scratch buffer, and be able to execute the scratch buffer code in the R process buffer. I've found how I could change the scratch buffer's mode to text by putting the following in the .emacs file:
(setq initial-major-mode 'text-mode)
Is there a similar statement I can put in my .emacs file that would make the scratch buffer have the ess-mode? I tried the following which results in an error about wrong type argument:
(setq initial-major-mode 'ess-mode)
What you want is (setq initial-major-mode 'R-mode). Alternatively, you could just do M-x R-mode when in the scratch buffer to change the major mode.
Related
I am very bad at customizing emacs. I desire that if i start with a file ending in ".r", emacs starts maximized, with two windows side by side (vertical division of the frame), in one my source code file, and in the other the ESS R interpreter. If I can understand the example, maybe I can generalize it to other extensions and modes. I still do not get the syntax of hooks in elisp.
The usual way to use Emacs is to have it always running instead of
opening and closing it all the time.
I suggest that you define a function that would make an existing Emacs
look the way you want:
(defun my-R-window-configuration ()
"Prepare the current emacs frame for R work."
(interactive)
;; maximimize the current frame:
(set-frame-parameter nil 'fullscreen 'maximized)
;; keep just the current window, presumably containing the R code
(delete-other-windows)
;; create ESS R interaction buffer and go there
(ess-switch-to-end-of-ESS)
;; go back to the code
(other-window 1))
Now you can do M-x my-R-window-configuration RET in an R buffer to get what you want.
I've just started using Fill Column Indicator for Emacs, which adds a vertical line on editing window to indicate the fill column.
I figured out that turn-on-fci-mode function could trigger the the bar.
I wanted it to start at the time when Emacs starts, so I also included it in the .emacs file.
The changes in the .emacs files are as follows:
(add-to-list 'load-path "~/.emacs.d/custom")
(require 'fill-column-indicator)
(turn-on-fci-mode)
Unfortunately, the line does not come up, even though running the function manually brings up the line.
fci-mode is buffer local. That means you need to turn it on for each buffer individually - setting it in your .emacs will set for one buffer, possibly just the splash screen, and not have any influence on the rest of your buffers.
To turn it on for all buffers, you need to use the following code in .emacs:
(define-globalized-minor-mode global-fci-mode fci-mode (lambda () (fci-mode 1)))
(global-fci-mode 1)
I'm looking to automate my development and I would like emacs to execute a few commands automatically when I load any file called "project.clj"
Specifically I'd like it to check the open buffers, and if there isn't a buffer called "swank" execute the clojure-jack-in command as if it came from the "project.clj" buffer,
and then I'd like it to run shell and speedbar as well, but I imagine once I figure out how to do the above, those will be easy.
I am a complete elisp noob, but I'm familiar with lisp in general.
You could do something like this:
(defun my-project-hook (filename)
(when (string= (file-name-nondirectory filename) "project.clj")
(do-stuff)))
(add-hook 'after-load-functions 'my-project-hook)
I'm trying to setup ipython.el in emacs23. I've successfully installed it (after putting python-mode.el in my load-path to supplant python.el which comes pre-installed with emacs). And I can even get it to run via M-x py-shell, etc.
The interface seems to be pretty poorly setup, and I was wondering if I was doing it wrong, or if I need to customize it to make it work the way I'd like.
In short, the workflow I'd like to have:
in one or more buffers, edit Python code
When I hit C-c C-c in that buffer, either execute the Python code in that buffer in the open IPython shell buffer (if there is one) or open up another buffer to do that.
But what happens right now is:
With the IPython shell in one buffer and the Python file in the other, if I hit C-c C-c in the Python file buffer, the file buffer switches to the IPython buffer (meaning I now have two, duplicated iPython buffers) and the file is executed.
This is annoying.
I'm pretty new to elisp, but my understanding of defadvice is that I could advise around python-execute-buffer to take note of the existing file buffer, run python-execute-buffer, and then switch back to the original file buffer as a workaround.
This seems pretty silly. Any suggestions for better ways to accomplish this would be appreciated!
If it matters: I'm on OS X 10.6.8 with IPython 0.10.1 running Emacs 24.0.50.
Thanks in advance!
Turns out that simply installing python-mode.el and anything-ipython.el and putting
(require 'python-mode)
(require 'ipython)
(require 'anything-ipython)
(add-hook 'python-mode-hook #'(lambda ()
(define-key py-mode-map (kbd "C-<tab>") 'anything-ipython-complete)))
(add-hook 'ipython-shell-hook #'(lambda ()
(define-key py-mode-map (kbd "C-<tab>")
'anything-ipython-complete)))
in my .emacs made everything work just how I wanted if py-shell is executed before py-execute-buffer (so that C-c C-c) executes the code in the shell instead of just opening up the *Python Output* buffer.
How do I apply a set of formatting rules to an existing source file in emacs?
Specifically I have an assembly (*.s) file, but I would like a generic command for all types of files.
I am trying to use M-x c-set-style with gnu style, but I am getting an error:
Buffer *.s is not a CC Mode buffer (c-set-style)
Open the file and then indent it by indenting the entire region:
M-x find-file /path/to/file RET
C-x h (M-x mark-whole-buffer)
C-M-\ (M-x indent-region)
Now, it looks like you're trying to apply C indentation to a buffer that's not in C mode. To get it into C mode
M-x c-mode
Or c++-mode, or whatever mode you want. But, since it's assembler code, you probably want assembler mode (which Emacs will do by default for .s files). In which case, the indentation command above (C-M-\ is also known as M-x indent-region) should work for you.
Note: the command sequence at the top can be rolled into a single command like this:
(defun indent-file (file)
"prompt for a file and indent it according to its major mode"
(interactive "fWhich file do you want to indent: ")
(find-file file)
;; uncomment the next line to force the buffer into a c-mode
;; (c-mode)
(indent-region (point-min) (point-max)))
And, if you want to learn how to associate major-modes with files based on extensions, check out the documentation for auto-mode-alist. To be fair, it's not necessarily extension based, just regular expressions matched against the filename.
Try M-x asm-mode. That will switch to assembler mode. Not sure how it will go with assembler embedded in the middle of a C file.
if you want indent current buffer
(defun iwb ()
"indent whole buffer"
(interactive)
(delete-trailing-whitespace)
(indent-region (point-min) (point-max) nil)
(untabify (point-min) (point-max)))
emacs will use the file name extension to identify the mode, you should add some assemble language mode style in your custom.el file
The major mode it's using for your .s files won't be cc-mode hence c-set-style makes no sense. However you can always manually enter cc-mode (M-x cc-mode) and then do the c-set-style you want. However as the C styles are keyed for C source code and not assembler this is almost certainly not what you want to do.
if you want to indent from the command line use :
emacs --batch <filenames.v> -f verilog-batch-indent