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

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

Jump to first non-whitespace character in line in emacs

[Origin]: http://superuser.com/questions/331221/jump-to-first-non-whitespace-character-in-line-in-emacs

I’m looking for the emacs equivalent of vi’s ^.

How can I move my cursor to the first non-whitespace character in a line?

shareimprove this question

The command is back-to-indentation, bound by default to M-m.

shareimprove this answer

Jump to first non-whitespace character in line in emacs

[Origin]: http://superuser.com/questions/331221/jump-to-first-non-whitespace-character-in-line-in-emacs

I’m looking for the emacs equivalent of vi’s ^.

How can I move my cursor to the first non-whitespace character in a line?

shareimprove this question

The command is back-to-indentation, bound by default to M-m.

shareimprove this answer

This is what I picked up from a previous Stack Overflow question:

(defun smart-beginning-of-line ()
  "Move point to first non-whitespace character or beginning-of-line.

Move point to the first non-whitespace character on this line.
If point was already at that position, move point to beginning of line."
  (interactive)
  (let ((oldpos (point)))
    (back-to-indentation)
    (and (= oldpos (point))
         (beginning-of-line))))
(global-set-key [home] 'smart-beginning-of-line)
(global-set-key "\C-a" 'smart-beginning-of-line)
shareimprove this answer

Is there a simple way to time a function call in elisp?

[Originally Posted By]: http://stackoverflow.com/questions/21246688/is-there-a-simple-way-to-time-a-function-call-in-elisp

I found exactly what I was looking for at http://nullprogram.com/blog/2009/05/28/

(defmacro measure-time 
    (&rest 
     body)
  "Measure and return the running time of the code block."
  (declare (indent defun)) 
  (let ((start (make-symbol "start"))) 
    `(let ((,start (float-time))) ,@body (- (float-time) ,start))))