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
Advertisements

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))))

How to automatically timestamp messages in *Messages* buffer?

[Originally posted by]: https://www.reddit.com/r/emacs/comments/3hagxf/how_to_automatically_timestamp_messages_in/

The following, by /u/wadcann, works for me in 24.5:

;; timestamps in *Messages*
;; via http://www.reddit.com/r/emacs/comments/1auqgm/speeding_up_your_emacs_startup/

(defun current-time-microseconds ()
  (let* ((nowtime (current-time))
         (now-ms (nth 2 nowtime)))
    (concat (format-time-string "[%Y-%m-%dT%T" nowtime) (format ".%d] " now-ms))))

(defadvice message (before test-symbol activate)
  (if (not (string-equal (ad-get-arg 0) "%s%s"))
      (let ((inhibit-read-only t)
            (deactivate-mark nil))
        (with-current-buffer "*Messages*"
          (goto-char (point-max))
          (if (not (bolp))
              (newline))
          (insert (current-time-microseconds))))))

after-init-hook vs eval-after-load/with-eval-after-load

[From]: http://emacs.stackexchange.com/questions/3624/after-init-hook-vs-eval-after-load-with-eval-after-load

Afaik, (add-hook 'after-init-hook ...) is the so-to-say brute-force approach to setting up customizations for packages.

No. If you want to configure packages in your init file, the typical approach is to call (package-initialize) at the top of the file, and then do the configurations. after-init-hook is unnecessarily complicated for this purpose.

However, eval-after-load and its more syntactically sugary with-eval-after-load seem more appropriate for more dynamic and fine grained configuration that plays well with the gradual, separate and lazy loading of extensions.

(with-)eval-after-load is used for things you want to do after a package is loaded. package-initialize doesn’t load the packages, it only “prepares” them (loads their autoloads).

If you use eval-after-load around every set of configurations, you won’t need to call (package-initialize) at the top. But what people usually do is to call (package-initialize), so that most configurations can be written straight to the init file, and then only eval-after-load code which is very long or which depends on the package being loaded.

shareimprove this answer