Undoing read-only region in emacs using ACL2 - acl2

I hit some strange incantation of keystrokes in emacs while using ACL2, and a region in my buffer becomes read-only. What can cause this? How do I unmark a region as read-only?

A Cause:
Suppose you have emacs-acl2.el loaded and the following in your ~/.emacs file:
(fset 'copy-and-advance
[?\C-t ?\C-e return ?\C-x ?o ?\C-\M-f ?\C-\M-f ?\C-\M-b])
(global-set-key "\C-tn" 'copy-and-advance)
(global-set-key (kbd "<backtab>") 'copy-and-advance) ; backtab is Shift+tab
Then performing the following causes the problem:
<switch to *shell* buffer>
ctrl+x b
shift+tab
<"SwitchSwitch" now appears as a read-only region at the prompt of my *shell* buffer>
A solution:
Put this in your ~/.emacs file and reload your ~/.emacs file (note the credit to stack overflow question 7410125):
(defun set-region-writeable (begin end)
"See http://stackoverflow.com/questions/7410125"
(interactive "r")
(let ((modified (buffer-modified-p))
(inhibit-read-only t))
(remove-text-properties begin end '(read-only t))
(set-buffer-modified-p modified)))
Then execute the above function with:
ctrl-x h
meta-x set-region-writable
<enter>

Related

ESS produces "Variable binding depth exceeds max-specpdl-size"

I am trying ESS (Emacs Speaks Statistics).
The problem is: Ctrl-P and the up-arrow are disabled on any buffer because of the following error:
Variable binding depth exceeds max-specpdl-size
The trigger is the following line in .emacs.el
(require 'ess-site)
This line is needed to load ESS. If I delete this line, then the problems does not happen, but, obviously, I can't use ESS.
Notes:
"(setq max-lisp-eval-depth 10000)" does not solve the problem.
"(setq max-specpdl-size 32000)" produces a different error:
Lisp nesting exceeds `max-lisp-eval-depth'
When the above two settings are valid, then I get the error for max-lisp-eval-depth.
This problem happens before M-x R RET. For example, it happens on the scratch buffer just after emacs starts.
I have not found any other key with this problem. (So Ctrl-F and down-arrow are working, for example.)
Deleting the ESS buffer does not solve the problem.
The initial message on the ESS buffer is following. (I don't know, whether it is useful.)
[ess-site.el]: ess-customize-alist=nil
[ess-site.el 2]: ess-customize-alist=nil
(S): ess-s-versions-create making M-x defuns for
(R): ess-r-versions-create making M-x defuns for
Environment:
emacs-ess-15.03.1-1.3.noarch
emacs-24.3-17.2.10.x86_64
R-base-3.1.1-2.1.9.x86_64
openSUSE 13.2 (Harlequin) (x86_64)
You could try
(setq max-specpdl-size 32000)
M-x describe-variable max-specpdl-size for some info
I've had this problem with python-mode and rope, never with ESS though.
Solution: change the order of certain settings.
My .emacs.el has settings for smooth-scrolling (A)
(require 'smooth-scrolling)
(setq smooth-scroll-margin 5)
and for the initial file (B)
(find-file "~/init.org")
(A) should be loaded before (B). (B) was loaded before (A) in my previous .emacs.el and this causes the problem. (I do not know the precise reason for the error which I described in my question.)

Refresh *R dired* buffer after executing command in inferior ESS process

I'd like to advise the inferior-ess-send-input interactive function to call my function which refreshes the *R dired* buffer automatically. I've tried using after and around as classes. For example:
(defadvice inferior-ess-send-input (around ess-revert-rdired-after-send activate)
ad-do-it
(call-interactively 'ess-revert-rdired-buffer))
I've also tried using after and even changed the source code of ESS to create a post-run hook. All of them had the same issue. I've even defined a new function which calls one after the other.
But I keep getting the message:
ess-error: ESS process not ready. Finish your command before trying again.
comming from ess-command. For some reason, adding this advice makes sprocess busy. Any ideas?
P.S.
Here the function is (work in progress):
(defun ess-revert-rdired-buffer ()
"If the buffer is live, update it. If it isn't start it."
(interactive)
(save-selected-window
(if (buffer-live-p (get-buffer "*R dired*"))
(save-excursion
(with-current-buffer "*R dired*"
(revert-buffer)))
(ess-rdired))))
I discovered that waiting 0.05 seconds was enough time for the process to get ready.

Emacs auto-complete for ESS in tooltip instead of buffer

I understand from the following resources:
http://www.emacswiki.org/emacs/ESSAuto-complete
http://www.emacswiki.org/emacs/AutoComplete
Emacs autocomplete-mode extension for ESS and R
Is it possible to get code completion for R in Emacs ESS similar to what is available in Rstudio?
...that I should have access to tooltips for auto-complete help in emacs when using ESS for R development. The last link additionally specifies that it should work out of the box with the latest ESS, and:
From version 12.03 ESS integrates out of the box with auto-complete
package.
Three sources ‘ac-source-R-args’, ‘ac-source-R-objects’ and
‘ac-source-R’ are included in ESS distribution. The latest combines
previous two and makes them play nicely together.
I know that in general, my emacs tooltips are possible because they appear correctly with my python jedi setup in emacs.
However, my emacs auto-complete does not work. Instead, there is a buffer at the bottom:
instead of this, with the help superimposed on the working buffer:
And I have the following in my init.el:
(require 'auto-complete)
(setq ess-use-auto-complete t)
(ess-toggle-underscore nil)
I have the following versions of:
ess 20131207.1141 installed No description available.
ess-R-data-view 20130509.458 installed Data viewer for GNU R
ess-R-object-popup 20130302.336 installed popup description of R object
auto-complete 20140208.653 installed Auto Completion for GNU Emacs
What am I missing?
UPDATE 1
Here's my init for ESS stuff. This produces completions in a buffer, but not in a tooltip, where some configuration options from the manual have been added. (I have now tried all permutations of commenting and not commenting all of these):
(require 'auto-complete)
(global-auto-complete-mode)
(require 'auto-complete-config)
(ac-config-default)
(require 'ess-site)
(setq ess-use-auto-complete t)
(setq ac-auto-start 2)
(setq ac-auto-show-menu 0.2)
(ess-toggle-underscore nil)
UPDATE 2
Similar question here, but the same solution is suggested which did not actually result in tooltips on my setup. But it suggests to me this might be a platform issue? The poster there was also on Ubuntu 12.04 as I am---is it possible the solutions that worked for VitoshKa, Alex Vorobiev, and Iqbal Ansari were on a different platform? Are you guys using OS X?
UPDATE 3
Maybe other diagnostics:
ac-source-R is a variable defined in `ess-r-d.el'.
Its value is ((prefix . ess-ac-start)
(candidates . ess-ac-candidates)
(document . ess-ac-help))
Documentation:
Combined ad-completion source for R function arguments and R objects
ac-source-R-objects is a variable defined in `ess-r-d.el'.
Its value is ((prefix . ess-symbol-start)
(candidates . ess-ac-objects)
(document . ess-ac-help-object))
Documentation:
Auto-completion source for R objects
ac-source-R-args is a variable defined in `ess-r-d.el'.
Its value is ((prefix . ess-ac-start-args)
(candidates . ess-ac-args)
(document . ess-ac-help-arg))
Documentation:
Auto-completion source for R function arguments
[back]
where the variables for ess-ac[TAB] are only...
Click <mouse-2> on a completion to select it.
In this buffer, type RET to select the completion near point.
Possible completions are:
ess-ac-R-argument-suffix
ess-ac-sources
So maybe the problem is my ESS install is lacking all ess-ac-* things defined above, like ess-ac-args, etc?
My auto-complete configuration also has
(require 'auto-complete-config)
(ac-config-default)
and after that setting ess-use-auto-complete makes ESS show the popup menus.
So as per your comments it turned out that auto-complete was not enabled in your emacs config. So just enable auto-complete by adding something like this in you init file
(load "auto-complete")
(global-auto-complete-mode)
Also for ESS you will need to set ess-use-auto-complete to t something like following would do
(setq ess-use-auto-complete t)
EDIT: ess-use-auto-complete is by default set to t so this step is not really needed.
Also since you found this option confusing I would recommend you to open an issue on the github repo so that the maintainers can improve the documentation (or code) whichever can reduce the confusion.
Auto-complete has a lot of configuration options do read the manual when you get time.
Glad I could help
Don't confuse eldoc with auto-completion. Eldoc is what you have in your screenshot, it shows all arguments of a function without being intrusive. Auto-completion pops up when you start typing stuff and activates after ac-auto-start characters.

Changing the home key behavior in an R session in emacs

I would like to change the behavior of the home key within an R session run from emacs. When I press the home key, it takes me all the way to the > prompt. I'd like the home key to take me to the start of the command entry (i.e., two points in from the start of the line). I assume that I can make this adjustments via my .emacs file; any guidance for the commands that I would need to add to that file would be appreciated. Thanks!
The behaviour you want is already available as C-a. You can rebind the home key with the following line:
(local-set-key (kbd "<home>") 'comint-bol)
There are a number of ways to get this to happen automatically when you are using the R session. I use something like the following:
;; Define the keybinding you want
(defun my-inferior-ess-mode-hook ()
(local-set-key (kbd "<home>") 'comint-bol))
;; add the key-binding to the hook that gets called whenever you start an R session:
(add-hook 'inferior-ess-mode-hook 'my-inferior-ess-mode-hook)
That's a bit much for a single key-binding, but you can extend the definition of my-inferior-ess-mode-hook to include a number of customizations you'd like to use.

user-input and ESS

When you ask ESS to evaluate the following from a buffer (C-c, C-b, or similar)
par(ask=TRUE)
plot(1,1)
plot(2,1)
The interpreter goes into a infinite loop because ESS starts the R session with the argument --no-readline. The loop can be broken with C-g, but is there any way to get the interpreter to actually request user input?
A solution is to edit ess-r-d.el and remove the hard-coded --no-runtime option given to R, it is line 127 of the latest implementation.
Change
(let* ((r-always-arg
(if (or ess-microsoft-p (eq system-type 'cygwin))
"--ess "
"--no-readline "))
to
(let* ((r-always-arg
(if (or ess-microsoft-p (eq system-type 'cygwin))
"--ess "))
If there is a compiled version, you have to compile the .el to generate and replace the binary .elc file.
The file may be (the location of the directory depends on your OS)
in the site-lisp directory. Edit the .el file in emacs (^X^F) then do M-x byte-compile-file to generate the .elc.
if you installed from the whole zip/tar source package, in the lisp directory. In this case, after the change, perform a make followed with a make install.
You need of course to have write access to the .el and .elc files.
If you do not feel comfortable with the compilation of the .el file, you may simply remove it (.elc) and use only the .el version (should be only a slight performance difference).
(Strategies gathered from Google and RSiteSearches):
Do you see the prompt : "hit Return" in any of your session windows? If so ... hit .
If not, then try clicking in the plot window.
And if that fails, you should get control back with c-G.
Edit: A further strategy, admittedly not solving the ESS-non-interactivity problem: If you want to hold for user input, then readLines can be used:
input=file("stdin")
print(readLines(input,1))

Resources