How to enter view-only mode when browsing Emacs source code from help?

[Origin]: http://emacs.stackexchange.com/questions/3676/how-to-enter-view-only-mode-when-browsing-emacs-source-code-from-help

When I browse Emacs help for functions via C-h f, I often want to peek into the Elisp/C implementation. I want to enter view-mode automatically when I access source code this way to avoid unnecessary modification. Is there a hook or function I can advise to accomplish this?

shareimprove this question

I use the alternative approach which you can specify entirely in your init file (as opposed to creating a .dir-locals.el file), and I simply make the files read-only rather than using view-mode. My config looks like this:

;; Emacs
(dir-locals-set-class-variables
 'emacs
 '((nil . ((buffer-read-only . t)
           (show-trailing-whitespace . nil)
           (tab-width . 8)
           (eval . (whitespace-mode -1))))))

(dir-locals-set-directory-class "/usr/local/src/emacs" 'emacs)
(dir-locals-set-directory-class "/usr/local/share/emacs" 'emacs)
(dir-locals-set-directory-class "/usr/share/emacs" 'emacs)

Obviously you can do the same thing for your elpa directory, and any other directory which contains third-party source code.

shareimprove this answer

How can I send the “&” (ampersand) character via AJAX?

[Origin]: http://stackoverflow.com/questions/11294107/how-can-i-send-the-ampersand-character-via-ajax

I want to send a few variables and a string with POST method from JavaScript. I get the string from the database, and then send it to a PHP page. I am using XMLHttpRequest object. The problem is that the string contains the character “&” few times, and $_POST array in PHP sees it like multiple keys. I tried replacing the “&” with “\&” with replace() function, but doesn’t seem to do anything. Can anyone help?

The javascript code and the string looks like this:

var wysiwyg = dijit.byId("wysiwyg").get("value");
var wysiwyg_clean = wysiwyg.replace('&','\&');

var poststr = "act=save";
poststr+="&titlu="+frm.value.titlu;
poststr+="&sectiune="+frm.value.sectiune;
poststr+="&wysiwyg="+wysiwyg_clean;
poststr+="&id_text="+frm.value.id_text;     
xmlhttp.open("POST","lista_ajax.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(poststr);

String is:

<span class="style2">&amp;quot;Busola&amp;quot;</span>
shareedit

You can use encodeURIComponent().

It will escape all the characters that cannot occur verbatim in URLs:

var wysiwyg_clean = encodeURIComponent(wysiwyg);

In this example, the ampersand character & will be replaced by the escape sequence %26, which is valid in URLs.

shareedit

Auto-refresh files when using tramp

[Origin]: http://emacs.stackexchange.com/questions/9338/auto-refresh-files-when-using-tramp

I am viewing remote log files using tramp mode in emacs. Is there a way to get tramp to auto-refresh these buffers when they change remotely? If this is not possible, is there a way to reload a buffer every time it is opened?

I have tried to set (global-auto-revert-mode t), but this does not work.


Edit: Just found out that this is intended behaviour:

You can also tell Emacs to revert buffers periodically. To do this for a specific buffer, enable the minor mode Auto-Revert mode by typing M-x auto-revert-mode. This automatically reverts the current buffer every five seconds; you can change the interval through the variable auto-revert-interval. To do the same for all file buffers, type M-x global-auto-revert-mode to enable Global Auto-Revert mode. These minor modes do not check or revert remote files, because that is usually too slow.

shareimprove this question

There is a customizable variable named auto-revert-remote-files, which does what you want.

shareimprove this answer

Mapping “jk” to Escape in Emacs’ evil-mode

[Origin]: http://blog.jenkster.com/2013/02/mapping-jk-in-emacs-evil-mode.html

I’m a Vim user. But more & more these days I find that one of my favourite versions of Vim is Emacs. Specifically, its evil-mode package, which is a very good Vim emulator1.

If you get started with evil-mode, one of the first questions you might ask is, “How do I remap ESC to something more finger-friendly?” Some people like to map jj. Personally I like jk, because it rolls off the fingers a little more easily.

Anyway, there are a couple of ways to do it in Emacs. The simplest & cleanest I’ve found is to install the key-chord package:

M-x package-install
key-chord

…then add this to your .emacs file:

(require 'key-chord)
(key-chord-mode 1)
(key-chord-define evil-insert-state-map  "jk" 'evil-normal-state)

Easy.

Filename in chinese shows as unicode characters

[Origin]: http://stackoverflow.com/questions/17961148/filename-in-chinese-shows-as-unicode-characters

when using C-x C-f, the filename which includes Chinese characters are shown as following:

How can I configure it to show Chinese words? Thank you.

=====updated=======

System: OS X 10.8.4

Emacs version: GNU Emacs 24.3.1 (x86_64-apple-darwin)

shareedit

I think this may be caused by one of those annoying interactions between the operating system and Emacs. Emacs doesn’t seem to know how to interpret the file names, so let’s try to help it by inserting this in your .emacs file.

(setq default-buffer-file-coding-system 'utf-8-unix)
(setq default-file-name-coding-system 'gb2312)
(setq default-keyboard-coding-system 'utf-8-unix)
(setq default-process-coding-system '(utf-8-unix . utf-8-unix))

You may need to try a different system instead of gb2312.

shareedit