Emacs, Auto Complete Mode, CSS, pain. (illustrated!) - css

I've got Auto Complete Mode installed for Emacs.
First: When I'm typing declarations I get the normal auto-complete behavior:
So I hit Tab to complete — no problem. But then I hit ;:
It instantly tries to complete something! And I can't hit Enter because that'll accept the erroneous completion!
So I have to hit C-j. What a pain.
Second: Once I'm done with a declaration, I type }:
...but it doesn't get indented properly unless I type Tab.
What gives?
Update, settings:
I'm using Emacs 23. My css-electric-keys are } and ;. My Auto Complete configuration is as follows:
(ac-config-default)
(setq ac-auto-start t)
(setq ac-delay 0.1)
(setq ac-auto-show-menu nil)
(setq ac-show-menu-immediately-on-auto-complete t)
(setq ac-trigger-key nil)

Here's a few suggestions:
(setq ac-auto-start t) starts autocomplete automatically. If you change that to (setq ac-auto-start 1) (or 2 or 3) then it will only start after that many characters have been typed. This might not solve your problem though if after you type the ;, it considers the entire preceding word as part of the current auto-complete search.
Maybe the problem is that it isn't recognizing the semicolon as a delimiting character (like whitespace), so it thinks you're still adding to the last word. Perhaps adding the semicolon string to ac-ignores would do the trick? (Not sure what the syntax for that would be)
Maybe you can prevent auto-completion via the enter key by adding: (define-key ac-complete-mode-map "\t" 'ac-complete) and (define-key ac-complete-mode-map "\r" nil). I'm not sure how this will interact with DWIM though (enabled by default).
Try adding semicolon as an auto-complete key?
My .emacs knowledge on a scale of 0 to 10 is like a 1.5, but maybe this will jog some better ideas.

Old stuff I know, but try the following:
(add-hook 'css-mode-hook
(lambda ()
(make-local-variable 'ac-ignores)
(add-to-list 'ac-ignores ";")))
From the manual

Related

Change auto indentation of comments [duplicate]

I am using the Emacs-Speaks-Statistics (ESS) mode for Emacs. When editing R code, any comment lines (those starting with #) automatically get tabbed to the far right when I create a new line above it. How should I change my .emacs.el file to fix this?
For example, I have:
# Comment
Now, after putting my cursor at the beginning of the line and pressing Enter, I get:
# Comment
Thanks for any hints.
Use '###' if you don't want the comments indented. According to the manual,
By default, comments beginning with
‘###’ are aligned to the beginning of
the line. Comments beginning with ‘##’
are aligned to the current level of
indentation for the block containing
the comment. Finally, comments
beginning with ‘#’ are aligned to a
column on the right (the 40th column
by default, but this value is
controlled by the variable
comment-column,) or just after the
expression on the line containing the
comment if it extends beyond the
indentation column.
Either
(setq ess-fancy-comments nil)
if you never want to indent single-# comments, or
(add-hook 'ess-mode-hook
(lambda ()
(local-set-key (kbd "RET") 'newline)))
if you want to change the behavior of Enter so it doesn't indent.
Setting ess-indent-with-fancy-comments to nil will remove the weird single-# indentation, but it must be set either buffer-locally in a hook (as in Rob's answer), OR before ESS is loaded:
(setq ess-indent-with-fancy-comments nil)
(require 'ess)
Other ways to make sure it is set before ESS is loaded, is to set it in M-x configure, or to set it in the :init section of use-package.
What's going on is that ESS defines styles at initialization in ess-style-alist, and then applies the default style in every buffer. So to make sure these styles respect ess-indent-with-fancy-comment, you must make sure to set it before the styles are defined.
Jouni's answer didn't work for me. But I found an approach here that does:
https://stat.ethz.ch/pipermail/ess-help/2016-May/010970.html
(defun my-ess-settings ()
(setq ess-indent-with-fancy-comments nil))
(add-hook 'ess-mode-hook #'my-ess-settings)

How to change smart assign key ("_" to "<-") binding in ESS

In emacs ESS, how do I correctly change the keybinding for ess-smart-S-assign?
What I tried is adding
(custom-set-variables
'(ess-smart-S-assign-key ":"))
to my .emacs, but that made weird things happen: When I press :, just a normal : appears. On the other hand, pressing _ once yields <- as usual, whereas pressing _ a second time then converts this to :.
The desired behavior would be to be able to use _ as a normal key, with : being converted to <-.
I am using the official emacs 24.3 for windows and the latest development version of ESS (14.06).
Here's the docstring for ess-smart-S-assign-key:
Documentation:
Key used by `ess-smart-S-assign'. By default bound to
underscore, but can be set to any key. If this key is customized,
you must add
(ess-toggle-S-assign nil)
(ess-toggle-S-assign nil)
after the line that sets the customization and evaluate these
lines or reboot emacs. The first call clears the default
`ess-smart-S-assign' assignment and the second line re-assigns
it to the customized setting.
So: put this in your .emacs file to get the desired behavior:
(setq ess-smart-S-assign-key ":")
(ess-toggle-S-assign nil)
(ess-toggle-S-assign nil)
Kind of ugly, but it works.
The accepted answer didn't work for me, but the following did:
(global-set-key (kbd "C-;") (lambda () (interactive) (insert " <- ")))
(ess-toggle-underscore nil)
Insert your shortkey choice instead of C-;.
Another solution is
(eval-after-load "ess-mode" '(define-key ess-mode-map (kbd "C-;") "<-"))
(eval-after-load "ess-mode" '(define-key inferior-ess-mode-map (kbd "C-;") "<-"))
This allows to restrict the binding change to ess-mode. Note that the second line defines the binding for the inferior R process.

Emacs Warning An error occurred while loading `.../.emacs.el':

When edit .emacs.el in emacs, I have run Alt + X eval-buffer command.
My os is windows.
And when I restart emacs it display following warning:
Warning (initialization): An error occurred while loading
`.../.emacs.el':
error: Non-hex digit used for Unicode escape
To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with the
`--debug-init' option to view a complete error backtrace.
.emacs.el is:
;;Open all fine in one running instance
;;Ref:http://www.johndcook.com/blog/2010/07/28/miscellaneous-emacs-adventures/
;;(server-start)
;;TEST
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
`(ansi-color-names-vector ["#242424" "#e5786d" "#95e454" "#cae682" "#8ac6f2" "#333366" "#ccaa8f" "#f6f3e8"])
`(custom-enabled-themes (quote (wheatgrass))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
;;Set auto save backup location, failed with following warning
(setq backup-directory-alist
`((".*" . ,"D:\Unix-Tmp")))
(setq auto-save-file-name-transforms
`((".*" ,"D:\Unix-Tmp" t)))
(require 'recentf)
(recentf-mode 1)
(setq inhibit-startup-screen t)
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
;;Aspell install failed
;;(setq-default ispell-program-name "C:/bin/Aspell/bin/aspell.exe")
;;(setq text-mode-hook '(lambda() (flyspell-mode t) ))
How I can resolve it?
The problem is these lines:
(setq backup-directory-alist
`((".*" . ,"D:\Unix-Tmp")))
(setq auto-save-file-name-transforms
`((".*" ,"D:\Unix-Tmp" t)))
The \U introduces a unicode escape ... and has to be followed by hex digits.
What you actually appear to want is a literal backslash character, so you need to escape it; i.e.
(setq backup-directory-alist
`((".*" . ,"D:\\Unix-Tmp")))
(setq auto-save-file-name-transforms
`((".*" ,"D:\\Unix-Tmp" t)))
Reference: http://www.gnu.org/software/emacs/manual/html_node/elisp/Basic-Char-Syntax.html#Basic-Char-Syntax
UPDATE
However, this appears to lead to another problem. A better solution would be to do what #Stefan suggests. Use "/" instead of "\" as the pathname separator. (It should work even on Windows ...)
Error is caused by D:\Unix-Tmp, \U introduces unicode escape as Stephen stated.
But when I change to :
(setq backup-directory-alist
`((".*" . ,"D:\\Unix-Tmp")))
(setq auto-save-file-name-transforms
`((".*" ,"D:\\Unix-Tmp" t)))
It will throw another:
Loading d:/git_root_tfs/WorkStation/Unix-Home/.recentf...done Cleaning
up the recentf list...done (0 removed) For information about GNU Emacs
and the GNU system, type C-h C-a. make-auto-save-file-name: Invalid
use of `\' in replacement text
At last I change the path to D:\Tmp-Unix and it works.
(setq backup-directory-alist
`((".*" . ,"D:\Tmp-Unix")))
(setq auto-save-file-name-transforms
`((".*" ,"D:\Tmp-Unix" t)))
Total .eamcs.el is
;;Open all fine in one running instance
;;Ref:http://www.johndcook.com/blog/2010/07/28/miscellaneous-emacs-adventures/
;;(server-start)
;;TEST
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
`(ansi-color-names-vector ["#242424" "#e5786d" "#95e454" "#cae682" "#8ac6f2" "#333366" "#ccaa8f" "#f6f3e8"])
`(custom-enabled-themes (quote (wheatgrass))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
;;Set auto save backup location, failed with following warning
(setq backup-directory-alist
`((".*" . ,"D:\Tmp-Unix")))
(setq auto-save-file-name-transforms
`((".*" ,"D:\Tmp-Unix" t)))
(require 'recentf)
(recentf-mode 1)
(setq inhibit-startup-screen t)
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
;;Aspell install failed
;;(setq-default ispell-program-name "C:/bin/Aspell/bin/aspell.exe")
;;(setq text-mode-hook '(lambda() (flyspell-mode t) ))
Always use forward slashes rather than backward slashes for file names in Emacs. Windows usually prefers backward slashes, but other than in a few rare exceptions, Windows actually accepts forward slashes just as well.
Emacs in Windows treats forward slashes (/) as backslashes (\). When you are specifying any type of path, you should always use forward slashes. Emacs will interpret them correctly. This allows you to control the escape sequence use to times where that is the intended effect.
C:/Users/username/AppData/Roaming/.emacs is a perfectly valid path/filename in Emacs.

How to stop emacs from replacing underbar with <- in ess-mode

ess-mode is "Emacs speaks statistics." This mode is useful for editing programs for R or Splus (two separate statistics packages).
In my buffer, when ever I type _ the character is replaced with <-, which is very frustrating. Is there an emacs lisp statement to turn off this behavior?
emacs: 22.1.1
ess-mode release (unknown)
From ESS's manual (look under "Changes/New Features in 5.2.0"):
ESS[S]: Pressing underscore ("_") once inserts " <- " (as before); pressing underscore twice inserts a literal underscore. To stop this smart behaviour, add "(ess-toggle-underscore nil)" to your .emacs after ess-site has been loaded
Since the feature is useful. You can assign it to other key which is less used by you in R it will automatically unassign it from underscore. I personally assign it to ";" by adding following line in .emacs file.
(setq ess-smart-S-assign-key ";")
My version of emacs is 24.3 All-in-one installation file by Vincent Goulet.(Installed on windows 7)
hope this helps
Edit
In emacs 25.2 above do not work instead add following in the .emacs file
(setq ess-smart-S-assign-key ";")
(ess-toggle-S-assign nil)
(ess-toggle-S-assign nil)
A more recent version which seemed to work for me, and is a lot less verbose (you essentially keep normal underscores, but can set your own key for this smart behaviour!):
(global-set-key (kbd "C-;") (lambda () (interactive) (insert " <- ")))
(ess-toggle-underscore nil)
Insert your shortkey choice instead of C-;.
From http://www.r-bloggers.com/a-small-customization-of-ess/ and
How to change smart assign key ("_" to "<-") binding in ESS
To assign ":" to "<-" and to stop the assignment of underscore (underbar) "_" to "<-" put the following in .emacs (yes, the repeated line is correct)
(setq ess-smart-S-assign-key ":")
(ess-toggle-S-assign nil)
(ess-toggle-S-assign nil)
(ess-toggle-underscore nil) ; leave underscore key alone!
Like Michał Marczyk and this R mailing list thread suggested, add this line to ~/.emacs:
(ess-toggle-underscore nil)
Then reload it with M-x load-file and type ~/.emacs.
But if you load the file again, e.g. if you add another customization, then it toggles it back to the original state. So toggle it twice, the first one forcing it to the default:
(ess-toggle-underscore t)
(ess-toggle-underscore nil)
That being said, I like Drummermean's solution better, but it also reverts back to default if you add it to ~/.emacs and load it twice. So force a toggle to the default before:
(ess-toggle-underscore t)
(global-set-key (kbd "M--") (lambda () (interactive) (insert " <- ")))
(ess-toggle-underscore nil)
I bound the smart assignment to Opt-[minus] like RStudio (on a Mac).
As a follow-up on #mmorin answer. To set keybinding for the assignment operator the same way as in Rstudio add the following in your .emacs file
(ess-toggle-underscore t)
(ess-toggle-underscore nil)
(define-key ess-mode-map (kbd "M--") (lambda () (interactive) (just-one-space 1) (insert "<-") (just-one-space 1)))
(define-key inferior-ess-mode-map (kbd "M--") (lambda () (interactive) (just-one-space 1) (insert "<-") (just-one-space 1)))

Emacs ESS Mode - Tabbing for Comment Region

I am using the Emacs-Speaks-Statistics (ESS) mode for Emacs. When editing R code, any comment lines (those starting with #) automatically get tabbed to the far right when I create a new line above it. How should I change my .emacs.el file to fix this?
For example, I have:
# Comment
Now, after putting my cursor at the beginning of the line and pressing Enter, I get:
# Comment
Thanks for any hints.
Use '###' if you don't want the comments indented. According to the manual,
By default, comments beginning with
‘###’ are aligned to the beginning of
the line. Comments beginning with ‘##’
are aligned to the current level of
indentation for the block containing
the comment. Finally, comments
beginning with ‘#’ are aligned to a
column on the right (the 40th column
by default, but this value is
controlled by the variable
comment-column,) or just after the
expression on the line containing the
comment if it extends beyond the
indentation column.
Either
(setq ess-fancy-comments nil)
if you never want to indent single-# comments, or
(add-hook 'ess-mode-hook
(lambda ()
(local-set-key (kbd "RET") 'newline)))
if you want to change the behavior of Enter so it doesn't indent.
Setting ess-indent-with-fancy-comments to nil will remove the weird single-# indentation, but it must be set either buffer-locally in a hook (as in Rob's answer), OR before ESS is loaded:
(setq ess-indent-with-fancy-comments nil)
(require 'ess)
Other ways to make sure it is set before ESS is loaded, is to set it in M-x configure, or to set it in the :init section of use-package.
What's going on is that ESS defines styles at initialization in ess-style-alist, and then applies the default style in every buffer. So to make sure these styles respect ess-indent-with-fancy-comment, you must make sure to set it before the styles are defined.
Jouni's answer didn't work for me. But I found an approach here that does:
https://stat.ethz.ch/pipermail/ess-help/2016-May/010970.html
(defun my-ess-settings ()
(setq ess-indent-with-fancy-comments nil))
(add-hook 'ess-mode-hook #'my-ess-settings)

Resources