text:
How to proceed on package.el signature check failure
I just tried to install ascii-art-to-unicode from the gnu repository (http://elpa.gnu.org/) via list-packages. I get the following error:
package--check-signature: Failed to verify signature
   ascii-art-to-unicode-1.9.el.sig: ("No public key
   for 474F05837FBDEF9B created at 2014-09-24T16:20:01+0200
   using DSA")

I'm using cask/pallet to manage my packages; is there some setup I missed? Some recent changes to elpa?
I'm using an emacs 24.4 pre-release.

I had a similar problem today updating org-mode from elpa (though I used package.el). Might be a temporary problem with their servers.

set package-check-signature to nil, e.g. M-: (setq package-check-signature nil) RET
download the package gnu-elpa-keyring-update and run the function with the same name, e.g. M-x package-install RET gnu-elpa-keyring-update RET.
reset package-check-signature to the default value allow-unsigned, e.g. M-: (setq package-check-signature "allow-unsigned") RET

This worked for me.
As stated in the package the following holds:
If your keys are already too old, causing signature verification errors when
installing packages, then in order to install this package you can do the
following:

Fetch the new key manually, e.g. with something like:
gpg --homedir ~/.emacs.d/elpa/gnupg --receive-keys 066DAFCB81E42C40

Modify the expiration date of the old key, e.g. with something like:
gpg --homedir ~/.emacs.d/elpa/gnupg \
    --quick-set-expire 474F05837FBDEF9B 1y

temporarily disable signature verification (see variable
`package-check-signature').

It shouldn't be necessary to explicitly run the function: installing the package should be sufficient because it should run the function for you automatically.

Ahh ok. Hard to test it now that it works, but I think you're right.

In case someone else is as confused as me: the command for step 3 is M-: (setq package-check-signature "allow-unsigned") RET with quotations

When trying to install gnu-elpa-keyring-update, I only get a [no match] message. Could you please help @joe_maya

@Leo try M-x package-refresh-contents before installing gnu-elpa-keyring-update, it should solve the [no match] issue

FWIW - I had this issue with the signature org-20140407.tar.sig.  Like Sigma's package-check-signature is/was allow-unsigned.
I changed the package-check-signature value to nil and the problem was resolved.

Thanks! I would never guess that "allow-unsigned" doesn't mean what it supposed to mean...

If you set it to nil, make sure you access the elpa.gnu.org repository via HTTPS, otherwise you're opening yourself to easy security attacks.

@avp: allow-unsigned means that you allow installing packages which don't have signatures.  But this package does have a signature (one you can't check because you don't have the needed key in your keyring)!

If you try to install the package gnu-elpa-keyring-update (which seems to have the purpose of updating the keys used by the package manager), you  will see in its description that you can do:
gpg --homedir ~/.emacs.d/elpa/gnupg --receive-keys 066DAFCB81E42C40
on the commandline to get new keys manually.  To make sure you are asking for the correct key (066DAFCB81E42C40 in the example above), check the error message that emacs gives you when you try to install any package.

this command gives me an error: "gpg: keyserver receive failed: Server indicated a failure" (Windows 10 Pro + WSL 2  +Ubuntu 18.04)

same on Ubuntu 18.04 (native)

It appears that the key used to sign this package (474F05837FBDEF9B) is indeed not published (therefore cannot be signed, therefore cannot be trusted).
But it would seem that package.el is supposed to fail gracefully (for now) in such cases:
;; If package-check-signature is allow-unsigned, don't
;; signal error when we can't verify signature because of
;; missing public key.  Other errors are still treated as
;; fatal (bug#17625).
(unless (and (eq package-check-signature 'allow-unsigned)
             (eq (epg-signature-status sig) 'no-pubkey))
  (setq had-fatal-error t))

So I'm wondering if for some reason your value of package-check-signature is different than its default value of allow-unsigned ?

package-check-signature is allow-unsigned; that leaves the epg-signature-status -- hmm.

sig=[cl-struct-epg-signature bad 474F05837FBDEF9B nil nil nil nil nil nil nil nil nil] status=bad - note that the problem is still present.

allow-unsigned means to allow installation of packages that are not signed, as opposed to packages which are signed but whose signature you're not able to verify.  This is used so you can install from ELPA archives which don't sign their packages (MELPA was like that last time I checked).

The answers here are a bit dated. This issue seems to have been fixed as of emacs 26.3.

Emacs 27.2 on Windows has the problem.

Alternatively, you could upgrade to a newer emacs, e.g. on Ubuntu:
sudo add-apt-repository ppa:ubuntu-elisp/ppa
sudo apt-get update
sudo apt-get install emacs-snapshot

This way you avoid doing all this: https://elpa.gnu.org/packages/gnu-elpa-keyring-update.html

get the puglic key with:
gpg2 --homedir ~/.emacs.d/elpa/gnupg --receive-keys 066DAFCB81E42C40

Attention:
your version could be a different key !

Setting package-check-signature to nil instead of the default allow-unsigned fixed this for me.
Fedora 29, GNU Emacs 26.2 (build 1, x86_64-redhat-linux-gnu, GTK+ Version 3.24.8)
 of 2019-04-30

how do I set "package-check-signature to nil" ? which file do I need to edit? init.el?

I get:
 % gpg --homedir ~/.emacs.d/elpa/gnupg --receive-keys 066DAFCB81E42C40
gpg: key 066DAFCB81E42C40: new key but contains no user ID - skipped
gpg: Total number processed: 1
gpg:           w/o user IDs: 1

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Mark and open multiple files with Helm and Projectile
Helm seem to support marking files in helm-find-files. Is it possible to open the marked files, each one inside of its own buffer from within the find file buffer?
Update: I noticed that I was using helm-projectile-switch-project rather than the Helm enhanced find-file command.

Yes, use C-SPC to mark each file individually or mark all with M-a, then press RET to open all those files. I wrote a Helm guide here that covers Helm basics and most of default commands. Also check my helm-projectile. It has the multifile opening right at the beginning.
Aside from the answer above, the question was updated with the question to open multiple files using helm-projectile-switch-project. To use helm-projectile-switch-project to switch to another project and open multiple files, either helm-projectile or helm-projectile-find-file must be set to projectile-switch-project-action:
(setq projectile-completion-system 'helm
      projectile-switch-project-action 'helm-projectile)

After that, you can open files in any project (including current projejct) without ever leaving your current working project. This is also explained in Enter project portal: helm-projectile-switch-project, C-c p p in my guide.

@Andrea It works a long time ago. Probably you didn't notice, or use find-file with Helm's completing-read, not helm-find-files.

Most probably I was too distracted with the task at hand and never noticed the buffers were actually being opened! Thanks.

I figured what's the problem: regardless of the marks I set, if I press RET over an unmarked file, then only that file will be opened in a buffer.

@Andrea No it's not. If you marked files, Helm always opens marked files regardless where the highlighter is.

Aha, you are right. Although that's not the case inside the helm completion buffer opened with Projectile!

@Andrea It's the same. Did you use helm-projectile-find-file command or projectile-find-file with Helm's completing-read? If not, you should activate helm-projectile with (helm-projectile-on). A demo at the top of my guide.

Let us continue this discussion in chat.

I think It's worth updating your answer to reflect the fact that setting the projectile-completion-system and projectile-switch-project-action variables did the trick for me.

@Andrea updated.

(setq projectile-switch-project-action 'helm-projectile)
(helm-projectile-on) ```

This worked for me
(projectile-mode +1)
(define-key projectile-mode-map (kbd "s-p") 'projectile-command-map)
;; projectile with helm
(projectile-global-mode)
(setq projectile-completion-system 'helm)
(setq projectile-switch-project-action 'helm-projectile)
(helm-projectile-on)

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
How can I quickly delete the trailing pathname component in ido-mode?
I use ido-mode for finding files and directories, which is generally very efficient in terms of keystrokes.
The one annoyance I've found is when deleting the trailing pathname component when using ido-find-file.  E.g., if the minibuffer contains /some/long/directory/path/and.some.long.file.name, I would like to quickly delete and.some.long.file.name with a single keystroke.  It seems hard to believe that this isn't built-in, but if so I haven't found the keybinding for it.
Is there a quick way to erase the trailing file name, or another efficient way of dealing with this?

There probably is, and an Ido user will no doubt help you with a good answer. I tried looking in the Ido manual. It's a mess, IMHO. The index is pretty much useless. If I were an Ido user I would ask for an improvement. As an Emacs user, I at least filed a bug report just now suggesting that the index be improved.

I didn't find a built-in way to do that (well M-^ C-k seems to work, but that's a little bit hacky). That said, implementing it doesn't look too difficult. I believe the following would do:
(defun ido-clear-fname ()
  (interactive)
  (setq ido-text-init ""
        ido-exit 'refresh)
  (exit-minibuffer))

(define-key ido-common-completion-map (kbd "<C-M-backspace>") 'ido-clear-fname)

This is pretty much exactly what I was hoping for, thank you!

M-backspace (Alt+Backspace) is quite efficient.  It'll kill whole words instead of single characters.  It's perhaps not a single key solution in your case, but you can use it pretty much everywhere in Emacs or in shell.

I found in my .emacs the following function which does work as expected:

(defun kill-back-to-indentation ()
  "Kill from point back to the first non-whitespace character on the line."
  (interactive)
  (let ((prev-pos (point)))
    (back-to-indentation)
    (kill-region (point) prev-pos)))

(global-set-key (kbd "C-M-<backspace>") 'kill-back-to-indentation)

Yes, this function is not ido-specific but rather for general purposes.

You can also just use this as the function body: (kill-region (point) (progn (back-to-indentation) (point))).

Be warned that C-M-<backspace> may log you out of your Linux session with no warning.

@nispio which distros do you mean?

I put the warning in because it happened to me, and took me totally by surprise.  After a little research, it looks like Ctrl+Alt+BackSpace is often the default binding for "Kill X-Window Session."  But since X is going away, newer distros may not have a similar binding. Just like all things Linux, YMMV. I am using GNOME desktop on RHEL 6.5, and that is the default setting.


text:
Run application in cwd on remote host from within eshell
I often use Eshell to connect to remote systems.  On those remote systems I sometimes want to run scripts in the current working directory.  In a regular terminal I'd type this:
./my-script.sh

Unfortunately, inside of Eshell this won't work:
~ $ cd /remote1:~
/ssh:remote1:/home/rekado $ ./my-script.sh
env: /ssh:remote1:/home/rekado/my-script.sh: No such file or directory
/ssh:remote1:/home/rekado $

It only works if I provide the complete TRAMP path to the script:
/ssh:remote1:/home/rekado $ /ssh:remote1:/home/rekado/my-script.sh
It works!
/ssh:remote1:/home/rekado $

Is there a way to convince Eshell to expand . automatically such that the simpler invocation just works?
As a workaround I currently use a function bound to C-c . that inserts the current full path on the command line.  I'd much prefer to have . just behave as expected.

That looks like a bug in eshell, you should report it.
I think you can fix it by
(defadvice eshell-gather-process-output (before absolute-cmd (command args) act)
  (setq command (file-truename command)))

Bottom-line, the problem is that tramp ends up constructing a remote command line of the form (I'm removing some escaping to make it clearer):
cd /home/rekado && exec env PS1='/ssh:remote1:/home/rekado $' /ssh:remote1:/home/rekado/my-script.sh

Which is why you end up with that "mysterious" message about env
What it needs to generate instead (and that's what's achieved by the command above) is something like
cd /home/rekado && exec env PS1='/ssh:remote1:/home/rekado $' /home/rekado/my-script.sh

I do believe the bug is on the eshell side though, since tramp has no way of knowing that "/ssh:remote1:..." is not a valid remote command (although if it was, we'd probably have a lot more problems with multi-hop tramp... but anyways). And eshell indeed does the sane thing when the command is explicitly a tramp path.

Works smoothly. Thanks for this solution.

It is a bug indeed and has been fixed upstream already.

@rekado, Which version of emacs is it fixed in?

I believe it was fixed with this commit: http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=882370eaa4f7ad6a88396dfdc64f896c727f87f4

I encountered this bug and had to apply the above fix (which corrects the problem --- thank you for that). I am running emacs 24.5.1 installed via homebrew on a mac. The upstream fix does not correct the problem for me.


text:
Attach to running remote shell with eshell/TRAMP/dtach
I often use GNU Screen to keep remote sessions alive.  Since I live in Emacs, I'd really like to be able to resume a running remote shell session from within Emacs.
GNU Screen implements all sorts of fancy things like terminal multiplexing and character drawing that I really don't need.  I'm really only interested in having detachable and resumable shell sessions, so something as simple as dtach might be sufficient.
I'm using this function to open an SSH session and reconnect to a running dtach session in shell-mode (taken from here):
(defun ssh-dtach (host)
  "Open SSH connection to remote host and attach to dtach session."
  (interactive)
  (let ((explicit-shell-file-name "dtach")
        (explicit-dtach-args '("-A" "/tmp/emacs.dtach" "-z"
                               "/bin/bash" "--noediting" "-login"))
        (default-directory (format  "/ssh:%s:" host)))
    (shell (format "*ssh %s*" host))))

Despite minor quirks, this works almost fine for shell-mode, but in Eshell this just starts a subprocess, so the terminal becomes very limited (e.g. no path autocompletion).
How can I configure Eshell to connect to a running dtach session upon connecting to a remote server?
EDIT:
As I thought about this problem again, I realised that it isn't entirely clear what I actually want.  Here's a list:

I want to stay in eshell, not in some subprocess
upon reattaching I want the output of the remote session to be replayed and the remote command history to be available
I want to be able to interact with a running remote process (e.g. a running yum install waiting for my input)

It seems that I'll need to write a bit of elisp code to make this all work with dtach.

shell-mode interacts with a shell process, eshell IS the shell -- so conceptually it seems to me you can't do what you want, unless you access a running emacs with an eshell buffer in the dtach session. Or am I mistaken here?

In eshell the lines between what is local and what is remote and what is an external command and an elisp function are blurred.  I'd like to make it even fuzzier such that remote running processes can be interacted with transparently as if they were local.  That would be almost the same as "resuming" a running session, I think.

Related: http://stackoverflow.com/questions/16819248/emacs-tramp-over-an-unreliable-connection

@sds: running screen inside of shell-mode is not going to work well, because screen needs more than a dumb terminal.

Maybe not satisfactorily, but this issue is on the Tramp wish list. Maybe it will be implemented some day.
See the discussion on the Emacs Devel ML http://thread.gmane.org/gmane.emacs.devel/174131


text:
How can I have Org use `sidewaysfigure` in LaTeX export?
I am writing an Org document with some large figures (images) which I would like to place on a separate page in landscape orientation when exporting to LaTeX.  In LaTeX I can achieve what I want by using \begin{sidewaysfigure}.  What is the easiest way to get Org to do this?
Google turns up this documentation, which mentions sideways tables but not sideways figures AFAICT, and this patch, which should add support for sideways figures, but I don't think it has been merged into the version I installed from the Org-mode ELPA repository.  (M-x org-version displays Org-mode version 8.2.9 (8.2.9-elpaplus @ […] ~/.emacs.d/elpa/org-plus-contrib-20141012/).
Is there an easy way to get this behavior with my current version of Org?
(Edited to add: It looks like the patch above has been merged into the bleeding-edge Org snapshot, so perhaps I should just install that.  However, I would still be interested to know if there is a way to get this functionality using the current stable release of Org from October 2014).

Doesn't it work if you just add \begin{sidewaysfigure}?

Not as well as I would like.  If I just add #+LATEX: \begin{sidewaysfigure} and #+LATEX: \end{sidewaysfigure} before and after, I get a figure environment within a sidewaysfigure, which does not render properly.  I could just drop down to LaTeX for the whole thing, of course, but I'd like to retain Org's ability to export to different formats as well if possible.

For the time being I've installed the latest Org revision from Git, which works very well for this, although it seems to have bugs in other areas (understandably).  If worst comes to worst I guess I can apply the :float sideways patch to the stable version locally.

Ah, I see. So the sidewaysfigure environment needs to replace the figure environment? Sounds like a job for exporti hooks. :-)

Using a current org version (at least 8.2.10, which is the one
currently shipped with Emacs), you can achieve what you want by simply using
#+begin_sidewaysfigure instead of #+begin_figure.
Try:
(with-temp-buffer (insert
"#+LATEX_HEADER: \\usepackage{rotating}
#+NAME: sideway
#+CAPTION: test
#+begin_sidewaysfigure
[[file:test.png]]
#+end_sidewaysfigure")
(org-mode)
(org-latex-export-as-latex nil nil nil t))

Result:
\begin{sidewaysfigure}
\caption{\label{sideway}test}
\includegraphics[width=.9\linewidth]{test.png}
\end{sidewaysfigure}

For html you could get:

which is then for you to fix via css or whatnot.

It seems this answer is saying to use a recent org version and use #+begin_sidewaysfigure instead of #+begin_figure. But it doesn't actually say that. Could you clarify?

Thanks for this answer.  I've since switched to using the most recent Org which has a specific option for sideways floats, but this will be very useful if I need other miscellaneous kinds of LaTeX environments in future.


text:
elisp: retaining data structure after inserting string representation to buffer?
I'm currently writing a major mode (for interacting with a remote Grid Engine) which involves fetching data, parsing it into an alist, formating the alist into a string and then inserting the formatted string into a buffer.  This is done for many rows of data.
Now I want to add a way for users to interact with the data in the buffer, e.g. to tab from one field to the next, or to press RET on a field to invoke a function on it.
It seems silly to me to "lose" the underlying data structure after rendering it to the buffer.  Parsing the line at point (e.g. with (thing-at-point 'word)) to partially recover the data structure just seems like a bad idea.
Here's an example of one of these alists:
((job-id   . 123)
 (priority . 0.844)
 (name     . "some job name")
 (owner    . "rekado")
 (state    . "r")
 (time     . "2014-10-24")
 (queue    . "standard")
 (slots    . 12))

This may be rendered with a format string like this:
(defun format-job-record (job)
  (format ""%-10s %-10s %-15s %-10s\n"
          (cdr (assoc 'job-id   job))
          (cdr (assoc 'priority job))
          (cdr (assoc 'owner    job))
          (cdr (assoc 'state    job))))

Is there an alternative way (an idiom perhaps), that allows me to specify a way to display this alist while keeping the underlying data intact?  I would like to be able to retrieve the whole alist when point is on the row, and any given field when point is on the rendered text for the field.
I think this might be done by storing the alist as special properties on the generated string, and by storing the field keys along with each individual field string, but I'm not sure if this is the best way to do it.
My goal is to separate representation in the buffer from the underlying data and only work on data structures instead of text.
What is the most "natural" approach to achieve this?
EDIT:
Is there a better more "disciplined" approach than what is outlined in my answer below, or are custom text properties the idiomatic way to go?

Here is what works in general as described above (associating text with data using the 'field property).  The string for each field is augmented with a 'field text property containing the underlying data.  The string for the whole row is augmented with a custom property prefixed with the name of the major mode (e.g. 'grid-engine-job) which contains the underlying data structure for the row.
(defun field-as-text (field obj &optional format-string)
  (let* ((value (cdr (assoc field obj)))
         (format-string (if format-string format-string "%s"))
         (text  (format format-string value)))
    (propertize text 'field value)))

(defun format-job-record (job)
  (let ((text (format row-pattern
                      (field-as-text 'job-id job)
                      (field-as-text 'priority job)
                      (field-as-text 'owner job)
                      (field-as-text 'state job))))
    (propertize text 'grid-engine-job job)))

To access the data one only needs to get retrieve the text property at point with (get-text-property pos prop), where pos is the position of point and prop is 'field or the custom property name (e.g. 'grid-engine-job).

Nice answer, I'd just use a propertize instead of the put-text-property.

@Malabarba Thanks! Updated the answer and my budding major-mode code.

A followup to @rekado's great answer -
I do this kind of thing all the time. I often put the entire alist on the buffer text (or on a string, depending on the use case), as a text-property value: (propertize string 'my-data the-alist).
It's worth pointing out, because it might not be obvious to everyone, that the actual data - not a copy of it, is being used as the property value (including in what @rekado described).
I mention this not because it means that there is little cost (just a pointer). It is important because it means that any changes to the object (the alist, or parts of it as in @rekado's example) are automatically reflected in any string or text that holds such a property. You always have access to the current state of the object.
And note that this trick works even when the propertized string is itself part of the object whose value is put on the string! (For example, the object is a cons whose car is the propertized string.) This kind of sharing is what nasty-old-side-effecty Lisp is about - as opposed to a functional language, for example.

tabulated-list-mode (used by list-packages) might be what you need.

Looking at the output produced by tabulated-list-mode, I see that it does indeed store information in text properties: tabulated-list-id, tabulated-list-entry, and tabulated-list-column-name.  Nice.


text:
How to indent back one level when writing a newline?
I'm using Emacs to write LaTeX. For example, in the following code, I have write to the level 3. When I press C-j, the cursor will indent to the third level. I what the newline to be indent at level 2.
How would I be able to do this?
\level 1
\level 1
  \level 2
  \level 2
     \level 3
     \level 3
  \level 2 % <- I want to end up here

Update: Thanks, I'm using sdaps package to write a survey. Here is a question example. BTW, I don't know list environment yet. Is it related to this?

Can you give a real use case?  The only scenario where I think this is useful is within list environments, and AUCTeX has good list support.  This is more-or-less the default behavior when using proper lists.

Thanks :) Re 'list environments': a 'list' environment is any environment in LaTeX that acts like a list, e.g. itemize, enumerate, and description.  That said, I'm having a hard time translating your 'levels' idea to  your tabular environments.  Can you explain a bit more?  :(

Just added a few explanation. This "back-indent" (or how to call this?) could be done by press a few buttons manuallly. But is there a hot key for this?

I think I understand now.
There are at least two ways you can get at the behavior you need, assuming you are using AUCTeX (which you should be if you are writing LaTeX):
C-c ] runs the command LaTeX-close-environment, which is an
interactive compiled Lisp function in `latex.el'.

It is bound to C-c ], <menu-bar> <LaTeX> <Close Environment>.

(LaTeX-close-environment &optional REOPEN)

Create an \end{...} to match the current environment.
With prefix-argument, reopen environment afterwards.

which will close the environment on a new line and advance point to the next line after that, or the even more convenient
C-c C-e runs the command LaTeX-environment, which is an interactive
compiled Lisp function in `latex.el'.

It is bound to C-c C-e.

(LaTeX-environment ARG)

Make LaTeX environment (\begin{...}-\end{...} pair).
With optional ARG, modify current environment.

It may be customized with the following variables:

`LaTeX-default-environment'       Your favorite environment.
`LaTeX-default-style'             Your favorite document class.
`LaTeX-default-options'           Your favorite document class options.
`LaTeX-float'                     Where you want figures and tables to float.
`LaTeX-table-label'               Your prefix to labels in tables.
`LaTeX-figure-label'              Your prefix to labels in figures.
`LaTeX-default-format'            Format for array and tabular.
`LaTeX-default-width'             Width for minipage and tabular*.
`LaTeX-default-position'          Position for array and tabular.

Both of these ease the insertion of LaTeX environments and take care of the indentation.

It is :) I encourage you to read more about AUCTeX with (info "AUCTeX"); there is so much you can do with it.  If you work with citations, RefTeX is equally indispensable.  If your documents have a lot of mathematics, preview-latex (bundled with AUCTeX) comes in very handy.

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
god-mode: swap keys
I'm using the Dvorak keyboard layout and have swapped C-x and C-t, because I find it easier to type on Dvorak.
(define-key key-translation-map [?\C-x] [?\C-t])
(define-key key-translation-map [?\C-t] [?\C-x])

I'm also using god-mode, though, so I'd like x to be swapped with t when in god-local-mode, such that typing x results in C-t and typing t results in C-x.  I have a very crude solution using keyboard-translate:
(defun my-god-swap-on ()
  (interactive)
  (keyboard-translate ?x ?t)
  (keyboard-translate ?t ?x))

(defun my-god-swap-off ()
  (interactive)
  (aset keyboard-translate-table ?t nil)
  (aset keyboard-translate-table ?x nil))

(add-hook 'god-mode-enabled-hook 'my-god-swap-on)
(add-hook 'god-mode-disabled-hook 'my-god-swap-off)

Although this works it is extremely inelegant as it modifies global state.  If I switched to a buffer where god-mode is not enabled, the translation would still be active.  I could add yet another hook for buffer switching to make sure that the translation is disabled when god-local-mode is inactive in the current buffer, but this seems like a very ugly mitigation technique.
Is it possible to restrict the effects to a keyboard translation to only a single minor mode?
If this is not possible, is there another more elegant way I could swap keys in god-mode?  I see that god-mode rewires all keys bound to self-insert-command to god-mode-self-insert, but this uses this-command-keys-vector to determine with what key it was called and I cannot seem to shadow the definition of this-command-keys-vector with a let binding to swap x and t in a wrapper before passing control to god-mode-self-insert.

FWIW, here's your solution in 'before' advice form:
n.b. this is untested (I don't use god-mode).
(defadvice god-mode-lookup-key-sequence (before my-swap-x-t)
  "Swap ?x and ?t KEY arguments."
  (case (ad-get-arg 0)
    (?x (ad-set-arg 0 ?t))
    (?t (ad-set-arg 0 ?x))))
(ad-activate 'god-mode-lookup-key-sequence)

This is exactly what I was looking for.  I knew there had to be a way to achieve this by advising the function, but I didn't know exactly how to do it.  Thanks!

The general solution is to modify god-mode so that it takes the key translation mechanism into account. This way, it will work with any key translation you've set or will set (C-h causing DEL is another common one).
I had the same problem so I filed a bug and wrote a patch that fixes it, at least for C- combinations. It changes the last sexp of key-string-after-consuming-key from:
(if key-string-so-far
    (concat key-string-so-far " " next-modifier next-key)
  (concat next-modifier next-key))

To:
(let* ((next-literal-key-string (concat next-modifier next-key))
       (translation (lookup-key key-translation-map
                                (read-kbd-macro next-literal-key-string t)))
       (next-interpreted-key-string
        (if translation
            (format-kbd-macro translation)
          next-literal-key-string)))

  (if key-string-so-far
      (concat key-string-so-far " " next-interpreted-key-string)
    next-interpreted-key-string))

I now use this:
(defun original-god-mode-lookup-key-sequence (&optional key key-string-so-far) ())
(fset 'original-god-mode-lookup-key-sequence (symbol-function 'god-mode-lookup-key-sequence))

(defun god-mode-lookup-key-sequence (&optional key key-string-so-far)
  "Wrap original-god-mode-lookup-key-sequence.  Swap x and t."
  (interactive)
  (case key
    (?x (original-god-mode-lookup-key-sequence ?t key-string-so-far))
    (?t (original-god-mode-lookup-key-sequence ?x key-string-so-far))
    (t (original-god-mode-lookup-key-sequence key key-string-so-far))))

It makes a copy of god-mode-lookup-key-sequence as original-god-mode-lookup-key-sequence and then overrides it with a wrapper that performs the swap for x and t.  It's not elegant, but at least it won't leak.

Maybe (defalias 'bar (symbol-function 'foo)) would be a simpler start?

It seems like a use-case for some 'before' advice, though. It could just change the argument if necessary, before the original function executes.


text:
Focus-hook: attenuate colours when losing focus
How can I use the focus hooks to attenuate all colours in visible buffers when the Emacs frame loses focus?
I tried using the following code:
(set-frame-parameter (selected-frame) 'alpha '(100 80))

To make the frame become translucent, but it would flicker when I hit Ctrl (apparently that's because I let GNOME highlight the mouse cursor when I hit Ctrl).
Making the frame transparent isn't what I want anyway.  Is it possible to desaturate all colours instead?
EDIT:  a less ambitious goal is to change/attenuate the colours of the mode line on focus change and restore them to normal when focus returns.  With two monitors I often find myself typing into the void when Emacs is displayed but not focussed, so I need some better visual indicator of focus.

While this Emacs feature sounds undeniably cool, I think it would be better to leave such a thing to the compositor you're using, compton for instance can dim inactive windows.

Well, I suppose that's one way to do it (and probably the right way to do it), but I don't really want this for any other window/application except for Emacs.  I guess I'd be happy with changing the colour of the modeline on focus change.

See if auto-dim-other-buffers-mode works for you.
Out of the box it dims frames when they lose focus as well as buffers when they lose current-buffer status.
It's available on MELPA.  Source here:
https://github.com/mina86/auto-dim-other-buffers.el

Sure.  See function doremi-increment-color in library doremi-frm.el.
In this case, you want to use a negative INCREMENT argument and specify s (for saturation) as the COMPONENT argument to increment (decrement, in this case).
You would call doremi-increment-color on any color of any UI feature you like (or on all of them), to calculate a less saturated version of the color.  See also function hexrgb-increment-saturation in library hexrgb.el.
You can get an interactive idea of applying this across the board by using command doremi-all-faces-bg+ or doremi-all-frames-bg+ (or the same, with fg+ instead of bg+).
More Do Re Mi color-changing described here.

With respect to your request about dynamically desaturating and saturating the mode line: See, for example, function 1on1-color-minibuffer-frame-on-setup in library oneonone.el, which does the same kind of thing for a standalone minibuffer frame. It uses function hexrgb-increment-hue, but you would use hexrgb-increment-saturation instead (or doremi-increment-color).
This is the meat of that function:
(set-background-color (hexrgb-increment-hue ; Change bg hue slightly.
                       (frame-parameter nil 'background-color)
                       1on1-color-minibuffer-frame-on-setup-increment))

Different answer based on your edit.
If you just want to change the mode line, check out what the Emacs manual has to say about mode-line-inactive face.

Like mode-line, but used for mode lines of the windows other than the selected one (if mode-line-in-non-selected-windows is non-nil). This face inherits from mode-line, so changes in that face affect mode lines in all windows.

You could make mode-line have a bright red background and mode-line-inactive a bland grey background, for instance.


text:
Can I include a common code block in two different code blocks in Org mode?
I have an org-mode file containing a table of data and two Python code blocks to extract different summaries from it.
I would like to share some common constants and functions between these two code blocks.  Ideally, I'd do this by factoring out the common code into a separate code block, which would be automatically included and evaluated whenever either of the other two blocks is evaluated.  In made-up syntax, it would look something like the following:
#+NAME: init_block
#+BEGIN_SRC python
  ... common constants and functions here ...
#+END_SRC

#+NAME: summary_1
#+BEGIN_SRC python :prepend init_block
  ... data-processing code depending on init code goes here ...
#+END_SRC

#+NAME: summary_2
#+BEGIN_SRC python :prepend init_block
  ... more processing which also depends on init code ...
#+END_SRC

I suppose I could use the :session option, but I would prefer not to, for two reason.  First, it sets up a stateful system, rather than one which runs from scratch each time I use C-c C-c on a code block.  Second, and relatedly, I now have to remember to manually evaluate the common initialization code each time I open the file: I can't just update the data table, go to one of the summary blocks and hit C-c C-c to update it.
Is there a good way to do this?

You can do this most easily using org-babel's noweb reference syntax for literate programming.  Here is an example:
* Initialization block containing function definition
#+NAME: init_block
#+BEGIN_SRC python
  constant=19
  def some_function(x):
    return constant * x
#+END_SRC

* Call the function on an integer
#+BEGIN_SRC python :noweb yes
  <<init_block>>
  return some_function(13)
#+END_SRC

#+RESULTS:
: 247

* Call the function on a string
:PROPERTIES:
:noweb:    yes
:END:

#+BEGIN_SRC python :noweb yes
  <<init_block>>
  return some_function('abc')
#+END_SRC

#+RESULTS:
: abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc

Thank you.  This looks great, much better than my hackish solution.  I will try it out in the next few days and see if I have any problems.

After thinking a little more I found a partial solution to this problem.  It does use :session, but I can at least ensure that the common initialisation code is always run automatically before evaluating one of the other blocks.  The 'trick' is to use a dummy header variable that refers to the header block, causing it to be evaluated each time:
#+NAME: init_block
#+BEGIN_SRC python :session t
  constant=19
  def some_function(x):
    return constant * x
#+END_SRC

#+BEGIN_SRC python :session t :var dummy=init_block
some_function(13)
#+END_SRC

#+RESULTS:
: 247

Now I can change definitions in init_block and have them automatically re-evaluated whenever another block which refers to it using :var dummy=init_block is evaluated.  This works well provided that the definitions in init_block are idempotent and stateless.
(Note that when changing Python blocks to :session mode you have to remove any return statements, which are needed in functional mode to return a value from the block).


text:
Display errors and warnings in an org-mode code block
I would like to be able to report warnings and errors when evaluating a Python code block in an Org file.
When a code block has Python syntax errors, Org helpfully pops them up in a separate buffer called *Org-Babel Error Output*.  It would be nice to be able to send my own warnings there too, while retaining the ability to return an array result to Org mode as a table using :results value.
To be clear, here is a dummy example of the kind of thing I thought might work:
#+BEGIN_SRC python
    import sys
    sys.stderr.write('Warning.\n')
    sys.stderr.flush()
    return [['Table', 'header'], ['table', 'data']]
#+END_SRC

#+RESULTS:
| Table | header |
| table | data   |

Edited to add: This discussion on the org-mode list suggests that error output is only displayed when the code-block evaluation fails.  So it looks like this is possible, but only by aborting the evaluation using exit(1) or similar.

Constantine's answer  works perfectly for me, if it is also a solution for you please accept the answer, if it isn't update your question, please.

As described by Eric Schulte on the org-mode mailing list (see the link in the question) we can modify org-babel-eval to achieve this:
(defvar org-babel-eval-verbose t
  "A non-nil value makes `org-babel-eval' display")

(defun org-babel-eval (command query)
  "Run COMMAND on QUERY.
Writes QUERY into a temp-buffer that is processed with
`org-babel--shell-command-on-region'.  If COMMAND succeeds then return
its results, otherwise display STDERR with
`org-babel-eval-error-notify'."
  (let ((error-buffer (get-buffer-create " *Org-Babel Error*")) exit-code)
    (with-current-buffer error-buffer (erase-buffer))
    (with-temp-buffer
      (insert query)
      (setq exit-code
        (org-babel--shell-command-on-region
         command error-buffer))

      (if (or (not (numberp exit-code)) (> exit-code 0)
              (and org-babel-eval-verbose (> (buffer-size error-buffer) 0)))
      (progn
        (with-current-buffer error-buffer
          (org-babel-eval-error-notify exit-code (buffer-string)))
        (save-excursion
          (when (get-buffer org-babel-error-buffer-name)
        (with-current-buffer org-babel-error-buffer-name
          (unless (derived-mode-p 'compilation-mode)
            (compilation-mode))
          ;; Compilation-mode enforces read-only, but Babel expects the buffer modifiable.
          (setq buffer-read-only nil))))
        nil)
    (buffer-string)))))

Now if org-babel-eval-verbose is set to t, output printed to stderr during evaluation of a source code block show up in a separate window just as if source code evaluation failed.

I found a solution based on Capturing-stderr-from-Python-in-org-mode-take-2:
(setq org-babel-python-command "python -i -c \"import sys;sys.stderr=sys.stdout\"")

But there are 2 issues:

this for some reason doesn't work with :session header argument.
there is an empty line before and after the result text block.

I've been struggling with "Unexpected Indent" errors. I'm not 100% sure it's caused by this approach, but I think it might be.


text:
How can I access an LDAP-Server to autocomplete address headers in message-mode/GNUS
I'm using GNUS to access a bunch of IMAP servers. When composing new messages it would be nice to have access to the companies ldap server for autocompletion on address headers TO/CC/BCC. Is this possible, and if, how?

Here are some patches that try to simplify EUDC configuration.

@legoscia this looks great; time to compile master again already? ;-)

[Update per comments]
Disclaimer: I'm not using EUDC or LDAP at this time, thus I have no current setup of it.
I've had success with EUDC in the past, it wasn't complicated to setup with autocompletion.
First, I copied exactly the configuration described in the EUDC wiki page.
The only thing that I recall being an issue was making sure that I had the right LDAP base, address and binddn fields setup.
I ended up setting credentials via M-x customize-group as I far as I know.
I then replaced all the related server fields with my configuration (Copying wiki stuff here, just for inline reference...).
(require 'ldap)
(require 'eudc)

(setq eudc-default-return-attributes nil
      eudc-strict-return-matches nil)

(setq ldap-ldapsearch-args (quote ("-tt" "-LLL" "-x")))
(setq eudc-inline-query-format '((name)
                                 (firstname)
                                 (firstname name)
                                 (email)
                                 ))

(setq ldap-host-parameters-alist
      (quote (("your_server" base "ou=addressbook,dc=your_dc_here,dc=fr"
               binddn "cn=admin,dc=your_dc_here,dc=fr"
               passwd "your_password"))))

(eudc-set-server "your_server" 'ldap t)
(setq eudc-server-hotlist '(("your_server" . ldap)))
(setq eudc-inline-expansion-servers 'hotlist)

(defun enz-eudc-expand-inline()
  (interactive)
  (move-end-of-line 1)
  (insert "*")
  (unless (condition-case nil
              (eudc-expand-inline)
            (error nil))
    (backward-delete-char-untabify 1))
  )

;; Adds some hooks

(eval-after-load "message"
  '(define-key message-mode-map (kbd "TAB") 'enz-eudc-expand-inline))
(eval-after-load "sendmail"
  '(define-key mail-mode-map (kbd "TAB") 'enz-eudc-expand-inline))
(eval-after-load "post"
  '(define-key post-mode-map (kbd "TAB") 'enz-eudc-expand-inline))

Please ellaborate on how you set it up/what you have as your configuration.  Link only answers are not recommended because the link can change in the future.

The linked config does not work for me (with the relevant parts filled in with correct values); the paramters used directly with ldapsearch at the commandline gets results, emacs apparently does not even try something; is there proper documentation somewhere?

I renounce anything I said -- it works now; somewhere in my attempts to get it working I added "scope 'subtree" according to the docs for other client-systems -- that got in the way; all I had to add was "-ZZ" to the ldap-ldapsearch-args for TLS.


text:
How should comint-derived modes keep track of buffers and processes?
Having written a couple of custom comint-derived modes, I often find it tricky to decide how to keep track of buffers and processes: for instance, to associate different source buffers with different interpreters.  Is it better to keep a reference to the buffer or the process?
Given a buffer, one can find its associated process using get-buffer-process.  Conversely, given a process, process-buffer returns its associated buffer.  Both buffers and processes also permit an extra layer of indirection by looking them up by unique name, but this seems fragile compared to just keeping a reference to the object itself.
One possibility seems clearly bad, since it violates the principle of storing data once-and-only-once: namely, keeping references to both the buffer and the process.
Most comint- functions for sending input take a process rather than a buffer as an argument, which argues for hanging on to the process object, not the buffer.  On the other hand, buffers tend to stick around longer than processes: a process might finish or be killed and a new process started in the buffer it previously used.
Are there other convincing arguments for referencing the process or its buffer?

For the reasons you provided, I generally prefer to hold on to the buffer.
Then I write a foo-proc function which returns the corresponding process, potentially re-starting it if needed.  And I even sometimes then write a foo-buffer function which calls foo-proc so that not only it gives me the buffer but it also ensures that the process is running.

Thanks, this is the kind of guidance I was looking for, and I'm not likely to find a better source!


text:
Fuzzy completion when inserting Unicode characters
I just discovered C-x 8 RET as a way to insert Unicode characters by Unicode name or hex code.  I have not (yet?) memorised all Unicode character names, so I don't always find the right character.
There is, for example, the character "SNOW CAPPED MOUNTAIN".  If I type just "MOUNTAIN" this character will not appear the completion list.  I need to remember to search for "SNOW" to see this particular character in the list of completions.
As someone who has become dependent on IDO for anything involving completion, this lack of flexibility is rather unnerving.  I use ido-ubiquitous-mode.
How can I use IDO-like matching for Unicode input?  How can I use flexible completion for ALL THE THINGS?
(I would be okay with abandoning IDO mode if there was something better.)

As a workaround for that same problem, I would type C-q SPC mountain TAB. That would match any character name with "mountain" as non-first word.

Have a look at http://emacs.stackexchange.com/a/3139/2094 for helm-based completion.

Hmm, this sounds like a bug you can report at the project's issue tracker.

If you type *cap*mou TAB, then you get the whole completion(s).

@Juancho that's true, but it's not the behaviour I want

@wasamasa indeed, it seems to be a bug.

As @wasamasa suggested, ido-ubiquitous should take care of completion when insert-char is used.  There is a bug report that was closed in 2013, but I still see this behaviour with Emacs 24.4 and ido-ubiquitous version 20140904.1547, so I filed another bug report.
EDIT:
The maintainer of ido-ubiquitous wrote this:

Ok, I figured out the problem. There are a lot of unicode characters, so the list of completions is exceeding ido-ubiquitous-max-items and ido-ubiquitous is disabling itself for that reason. On my system, there are almost 40k completions available, and the default for ido-ubiquitous-max-items is 30k. Setting it to 50k enables ido completion for insert-char for me. So try customizing that.

Indeed, (setq ido-ubiquitous-max-items 50000) fixes it.

For ido-completing-read+, use (setq ido-cr+-max-items 50000) to fix this error.

Neither flag is working for me with ido-completing-read+.

To get snow capped mountain included when you just type mount, you may want to do:
(push '(unicode-name (styles substring)) completion-category-overrides)

Actually, maybe this substring style should be enabled by default for unicode names, like it is for buffer names.  Maybe you should lobby for it via M-x report-emacs-bug.

If you use Icicles then C-x 8 RET lets you use substring or regexp or fuzzy matching during completion.  And you can use progressive completion, to match against multiple (e.g. simple) patterns.
In addition, if option icicle-read-char-by-name-multi-completion-flag is non-nil, which it is by default, then you can use multi-completion to match against any combination of these:

the Unicode name
the Unicode code point, as a hexidecimal numeral
the character itself (as it appears in text, not an integer)

Completion candidates you see in buffer *Completions* contain all of these components - WYSIWYG.
Why might you want to match against the character itself?
To see the corresponding Unicode code points and character name(s),
including any old names.  For example, for the character `
(grave accent) you get these two completion candidates:
GRAVE ACCENT      60      `
SPACING GRAVE     60      `

I think I should really try Icicles one day.  Thanks for your answer.

You can use command apropos-char in library apu.el to show all of the Unicode chars whose names match a regexp or list of words you type.  By default, words are matched as substrings.
In the list of matches, you can hit ^ to insert the char shown on the current line into the buffer where you invoked apropos-char, at point.  Or you can hit C-y to copy that char to the kill ring (or M-y to copy it to the secondary selection). (Hit RET to see more info about the char.)

You can customize it:
Completion Category Overrides:
Alist:
INS DEL Category: Value Menu unicode-name
            Properties to override:
            [X] Completion Styles:
                Select a style from the menu;
                insert a new menu to add more styles:
                INS DEL Choice: Value Menu substring
                INS
            [ ] Completion Cycling:
                Select one value from the menu.
                Choice: Value Menu No cycling
INS
    State : SAVED and set.
   List of category-specific user overrides for completion styles. Hide
   Each override has the shape (CATEGORY . ALIST) where ALIST is
   an association list that can specify properties such as:
   - ‘styles’: the list of ‘completion-styles’ to use for that category.
   - ‘cycle’: the ‘completion-cycle-threshold’ to use for that category.
   Categories are symbols such as ‘buffer’ and ‘file’, used when
   completing buffer and file names, respectively.
   This overrides the defaults specified in ‘completion-category-defaults’.


text:
How to display several pages of a PDF simultaneously in Docview?
I'm using Emacs, AUCTeX, and latex-preview-pane-mode to create a PDF presentation. However, the preview only displays one page at a time.
Is this the only way? It wastes some of the vertical space available on the screen.
Is it possible for Docview to preview several pages of a PDF in one page?

How about (setq doc-view-continuous t) and then (if needed) shrink the size of the pages that are visible?

@lawlist: At least for me, all that does is let C-n and C-p move between pages. While that's quite handy, it still only displays one page at a time.

I see -- after some Googling, it looks like your feature has been an ongoing discussion on the Emacs mailing lists for several years, but I don't think that feature exists yet.

I don't remember this specific functionality being discussed, but it would actually make a lot of sense for doc-view-continuous to behave like you want (i.e. just display all the pages one below the other).  You should probably request it via M-x report-emacs-bug.

Hi, I noticed that you are using doc-view in windows 7, can you share how you did it?

Currently there is no support for displaying several images in the same window, so there are two workarounds:

split the right window to display two slides at the same time.  As there is no way to send commands to two windows at the same time this is rather pointless, though, as one of the windows will stay fixed when you press n or p in the other window.  You might be able to overwrite this, but it seems messy.
you could try to affect the pdf-to-image conversion.  While ghostscript itself does not seem to allow rendering multiple pages to the same image file you may be able to replace the ghostscript executable (by setting doc-view-ghostscript-program) with a wrapper that calls ghostscript and then zips up the images in pairs, e.g. with ImageMagick's montage.

Neither of these two methods is particularly appealing.
Unfortunately, mudraw (which can be used as an alternative renderer) also does not support rendering multiple pages to the same image file.


text:
Display images in eshell with `iimage-mode`
My default shell is eshell.  I just discovered iimage-mode that allows me to display images in buffers that contain some reference to an image file.  Unfortunately, I doesn't seem to have any effect when it is enabled in eshell.
In any other buffer something like file:///home/rekado/Pictures/test.png is replaced with an inlined image loaded from the file test.png.  In an eshell buffer, however, I cannot seem to make this work.
I tried echoing the string file:///home/rekado/Pictures/test.png, but this just results in a boring string and no pretty test image.  I also made sure to use /bin/echo instead of the elisp/eshell implementation of echo, but with no success.
When I disable and reenable iimage-mode it works all right (the file name is replaced with an inline image), but that's a rather inconvenient workaround.
If there's no way to make eshell work with iimage-mode maybe there is another method to display images right in the eshell buffer?

Based on itsjeyd's answer I advised eshell/cat to display images when an argument is the filename of an image file supported by iimage-mode.
(defun my/iimage-mode-refresh--eshell/cat (orig-fun &rest args)
  "Display image when using cat on it."
  (let ((image-path (cons default-directory iimage-mode-image-search-path)))
    (dolist (arg args)
      (let ((imagep nil)
            file)
        (with-silent-modifications
          (save-excursion
            (dolist (pair iimage-mode-image-regex-alist)
              (when (and (not imagep)
                         (string-match (car pair) arg)
                         (setq file (match-string (cdr pair) arg))
                         (setq file (locate-file file image-path)))
                (setq imagep t)
                (add-text-properties 0 (length arg)
                                     `(display ,(create-image file)
                                               modification-hooks
                                               (iimage-modification-hook))
                                     arg)
                (eshell-buffered-print arg)
                (eshell-flush)))))
        (when (not imagep)
          (apply orig-fun (list arg)))))
    (eshell-flush)))

(advice-add 'eshell/cat :around #'my/iimage-mode-refresh--eshell/cat)

This allows me to display images right in the eshell buffer and to concatenate images and text alike.  There's probably a more elegant way to do this (and a safer way in case iimage-mode is not enabled), but I'll just leave it like this for now until it bites me.

Based on what happens behind the scenes when you call iimage-mode, you can define a function that takes care of displaying images for you, and have Emacs run this function every time you issue an echo command in Eshell:
(defun iimage-mode-refresh (command args)
  (when (string= command "echo")
    (let ((image-path (cons default-directory iimage-mode-image-search-path))
          file)
      (with-silent-modifications
        (save-excursion
          (eshell-previous-prompt 0) ; Start scanning from most recent prompt
                                     ; to avoid having to re-display all images.
          (dolist (pair iimage-mode-image-regex-alist)
            (while (re-search-forward (car pair) nil t)
              (when (and (setq file (match-string (cdr pair)))
                         (setq file (locate-file file image-path)))
                (add-text-properties (match-beginning 0) (match-end 0)
                                     `(display ,(create-image file)
                                               modification-hooks
                                               (iimage-modification-hook)))))))))))

(add-hook 'eshell-named-command-hook 'iimage-mode-refresh)

The main difference between this function and the function that gets run when you enable iimage-mode (iimage-mode-buffer) is that it does not check the whole buffer for image references. Instead, it starts scanning from the most recent prompt, which means that calling the function does not become more expensive as the *eshell* buffer grows in size. Each invocation of the function will cause only a single additional image (i.e., the most recent image you requested) to be displayed.
Note that existing images stay visible, i.e., they are not "reset" to strings representing file paths.

Thanks, this doesn't look bad.  I think it would be even better to turn this into a separate eshell command instead of a hook that's linked to the execution of echo.

It's a pity that iimage.el doesn't expose some other function that we could cleanly reuse.  As it stands, iimage-mode-refresh is almost a complete copy of iimage-mode-buffer.

@rekado "I think it would be even better...": You might want to consider adding your own answer with a modified version of the code. It sounds like you're up to the task. Also, we should delete the first four comments, as the information they contain has become misleading.

I just posted an answer in which eshell/cat is extended to work with images.

I have the similar problem at markdown-mode ,when I want to display images in xxx.md alive. I just glance at the iimage.el , And I find out (iimage-mode-buffer iimage-mode) this works fine for me.
(defun my-md-screenshot ()
   "Take a screenshot into a time stamped unique-named file in the
same directory as the org-buffer and insert a link to this file."
(interactive)
(setq filename
    (concat
     (make-temp-name
      (concat (file-name-base)
              "_"
              (format-time-string "%Y%m%d_%H%M%S_")) ) ".png"))
(call-process-shell-command "screencapture" nil nil nil
                          (concat " -i ~/public/img/" filename))
(insert (concat "![image](/public/img/" filename ")"))
(iimage-mode-buffer iimage-mode)
)

I did something similar, but using the standard library image capabilities of emacs instead of iimage mode. As a result, you don't need to have the mode enabled:
;; To know if I need to print as image or I need to default to the default eshell/cat
(defun my-is-imagep (filename)
  (let ((extension (file-name-extension filename))
        (image-extensions '("png" "jpg" "bmp")))
    (member extension image-extensions)))

;; Creates a space with display properties. Feel free to change `eshell/println` to `insert` and use it in a normal emacs buffer, it will inline the path given in `file`.
(defun my-print-image-eshell (file)
  (eshell/printnl (propertize " " 'display (create-image file))))

;; If image, use `my-print-image-eshell`. Otherwise, just use `eshell/cat`.
(defun eshell/mycat (&rest args)
  (interactive)
  (mapc (lambda (arg)
          (if (my-is-imagep arg)
              (my-print-image-eshell arg)
            (eshell/cat arg)
            )
          ) (-flatten args))
  nil)

The key is to create some bogus output (a space in this case), add some magic display properties (read more here) and use eshell/printnl to print that magic space that displays as your image.
Then, you can alias cat mycat $* in your .emacs/eshell/alias file.
You'll quickly face the problem of very big images slowing down emacs and not fitting in the screen, which forces the point to scroll down; they won't even show. This is some quick and dirty code that generates a thumbnail sized image for them and displays that instead. It could give you some ideas to implement something more robust (checking for errors, etc.). It requires imagemagick to be installed. If you emacs was compiled with support for it, you don't need the shell commands and you can use library functions instead:
(defun my-is-imagep (filename)
  (let ((extension (file-name-extension filename))
        (image-extensions '("png" "jpg" "bmp")))
    (member extension image-extensions)))

(defun my-get-image-width (filename)
  (string-to-number
   (shell-command-to-string
    (format "convert '%s' -ping -format \"%%w\" info:" filename))))

(defun my-rescale-image (filename)
  "Rescale an image to a maximum width, or leave untouched if already small. Returns the new file path."
  (let ((file (make-temp-file "resized_emacs"))
        (max-width 350))
    (if (> (my-get-image-width filename) max-width)
        (progn
          (shell-command-to-string
           (format "convert -resize %dx '%s' '%s'" max-width filename file))
          file)
      filename)))

(defun my-print-image-eshell (file)
  (eshell/printnl (propertize " " 'display (create-image file))))

(defun eshell/mycat (&rest args)
  (interactive)
  (mapc (lambda (arg)
          (if (my-is-imagep arg)
              (my-print-image-eshell (my-rescale-image arg))
            (eshell/cat arg)
            )
          ) (-flatten args))
  nil)


text:
message-mode: delete recipient easily
When I'm composing a message in message-mode I sometimes want to remove a recipient from a long list of recipients on the To: line.  It seems that there is no semantic kill command that would delete a complete recipient.
I could zap to the next delimiter, I suppose, but the different formats available for recipients and their display names makes this a lot harder.  When on a To:, Cc: or Bcc: line, I really don't need to be able to delete words or sentences or s-expressions, I just need to be able to remove a recipient as a syntactic unit.
How can I easily augment kill-sexp to remove a recipient (i.e. name and email address in the various common formats) when I'm on a recipient line?

message-kill-address (C-c M-k) gets you most of the way there: it will kill from point to the end of the address.  You would need to advise/adapt it to go to the beginning of the address to have complete functionality.
For what it's worth, message-kill-address relies internally on message-skip-to-next-address, but as far as I can tell, there's no analogous message-skip-to-previous-address.  You could probably adapt the former to get a working version of the latter.


text:
CSS code completion as in Firebug
One of the convenient features of in-browser inspectors like Firebug is that it is so easy to tweak CSS stylesheets.  As you type in the attribute position, all possible attributes are shown in a dropdown list and can be picked from.  On the right hand side of a declaration, input is restricted to only valid values (which for some attributes is really just a very small number of values).
I'm looking for a CSS mode that makes editing CSS stylesheets easier by offering sensible contextual completion suggestions, or that even restricts my inputs to only valid values.  Does anything like that already exist?

company-mode provides slightly better results than auto-complete using the bundled company-css backend.
You get completion of property names (up-to-date with the current state of CSS3, AFAIK), and some completion of property values, where they are simple, like a fixed set of options.

I've grown quite attached to auto-complete mode, not least because it's an official part of Emacs.  Maybe I should just extend the ac-sources for css-mode with whatever company-mode offers over auto-complete at the moment.

It's absolutely not an official part of Emacs.

Dmitry: you are right, I was mistaken.  I remembered reading about autocomplete and company on the emacs-devel mailinglist (where rms asked about what popular packages are not yet included with Emacs) and I misremembered the information given there.  Thanks for correcting me.  I shall try company-mode.

I'm using company-mode now, but completion of property values is elusive.  Completion for property names is good, though.

@rekado "completion of property values is elusive" Feel free to create an issue with your complaints. But indeed, implementing smart completion logic for values is hard.

auto-complete offers contextual completion for values of CSS properties:

The default setup for auto-complete (which will also enable completion in css-mode buffers) is:
(require 'auto-complete-config)
(ac-config-default)

If you want to enable auto-complete for css-mode buffers only, add the following to your init-file:
(require 'auto-complete-config)

(defun css-setup-ac ()
  (setq ac-sources '(ac-source-dictionary ac-source-words-in-same-mode-buffers))
  (ac-css-mode-setup)
  (auto-complete-mode 1))

(add-hook 'css-mode-hook #'css-setup-ac)

I don't know of any existing modes that restrict property values to valid values.

There is no completion for property names, though; I only see completion for values.


text:
hippie-expand disturbes paredit
paredit restricts my editing freedom to guarantee me that my s-expressions are never unbalanced.  Unfortunately, hippie-expand doesn't care a bit about rules and manages to disturb the balance by expanding to syntactically wrong text (e.g. text containing a couple of parentheses more than would be appropriate in the current context).
Cleaning up after the hippie is a chore; I have to disable paredit temporarily to delete the superfluous parentheses and reenable it afterward.
Can the hippie be made aware of paredit's efforts to keep the buffer clean?  Is there an alternative expansion feature that is more well-behaved when paredit is around?  Or is there a way to make paredit (or something like it) clean up invalid expansions automatically?

Not an answer, but you can directly insert parentheses with C-q (, and you can delete parentheses by marking them and killing the region with C-w. Those aren't overridden by paredit's own commands.

The problem you mentioned is why I remove the functions try-expand-line and try-expand-list from the list of functions hippie-expand uses to produce expansions. This doesn't really solve the problem but may be an acceptable workaround.
(dolist (f '(try-expand-line try-expand-list))
  (setq hippie-expand-try-functions-list
        (remq f hippie-expand-try-functions-list)))

So hippie-expand will still complete words, symbols, etc., but not full lines or lists - the things that are probably introducing excess delimiters.


text:
Stop at beginning of a word on `forward-word`
I often use multiple invocations of forward-word followed by a single backward-word to move point to the beginning of a word on a line.  I guess I never got used to the way forward-word differs from vim's w and even after years of using Emacs I cannot get used to the difference.
Is there a function I could use instead of forward-word that doesn't jump over words but stops at the beginning of a word as well?  Are there other strategies to move to the beginning of a word when moving point forward that don't involve repeatedly executing forward-char?

You may (at some point) be interested in writing your own forward/backward word/paragraph and related kill-word functions.  The following are three links to some custom functions that I use on a daily basis -- the behavior closely resembles certain word processors that I have used over the years:  http://stackoverflow.com/a/20456861/2112489 | http://stackoverflow.com/q/18675201/2112489 | http://superuser.com/a/685604/206164

The misc package (shipped with emacs) has the built-in function forward-to-word, which does what I think you want:
forward-to-word is an interactive compiled Lisp function in `misc.el'.

It is bound to M-f.

(forward-to-word ARG)

Move forward until encountering the beginning of a word.
With argument, do this that many times.

To use it, first add (require 'misc) to your config file.

Thanks, this is useful.  Unfortunately, this doesn't also stop at the end of a word, though.

True, but neither does vim's w.  As far as I can see, there is an almost perfect vim-to-emacs mapping: w = forward-to-word; e = forward-word; b = backward-word; ge = backward-to-word.  But I'm not an expert vim user, so maybe there is some subtlety I am missing.

Heh, you are in fact right.  I guess whenever I'm in vim w, e, and b just blur away and I just move around.  Weird.  I was certain w stopped at both points!  So, I'll accept your answer, because it exactly fits my question :)

You can bind the below function to M-f and bind the original forward-word to M-F. This function simply takes the arg and passes it on to the forward-word function. So the universal arguments will work just as fine as with the original function.
(defun modi/forward-word-begin (arg)
  "Move forward a word and end up with the point being at the beginning of the
next word.  Move point forward ARG words (backward if ARG is negative).
If ARG is omitted or nil, move point forward one word."
  (interactive "p")
  (forward-word arg)
  (forward-word 1)
  (backward-word 1))

Word of caution though that the above function might not always do the right thing; it's very much dependent on if the point is already on the beginning of a word or not.

Here's another way of implementing the above where the word boundary is not as per the syntax table but strictly on whitespace separation:
(defun modi/forward-word-begin (arg)
  "Move forward ARG (defaults to 1) number of words.
Here 'words' are defined as characters separated by whitespace."
  (interactive "p")
  (dotimes (_ arg)
    (forward-whitespace 1)))

Credit goes to @glucas for this idea.

After a long and painful search for the perfect 'forward/backward-word' functions I found the following with which I am now very happy:
(progn
  (defun boundary ()
    (and      (= (char-syntax (char-after))  ?w)
         (not (= (char-syntax (char-before)) ?w))))
  (defun my-forward-word ()
    (interactive)
    (while (progn (forward-char)  (not (boundary)))))
  (defun my-backward-word ()
    (interactive)
    (while (progn (backward-char) (not (boundary)))))
  (global-set-key [M-right] 'my-forward-word)
  (global-set-key [M-left]  'my-backward-word)
  )

If you're willing to use evil,  w in normal state is bound to evil-forward-word-begin, which is the Vim-style functionality you're after.

I used to use evil a long time ago, but since a while I use god-mode and regular Emacs bindings instead.

I often use multiple invocations of forward-word followed by a single backward-word to move point to the beginning of a word on a line.

As you mention, the trick is to go two words forward, then one word backwards.
The following should do the trick and should respect other modes like subword mode.
(define-key global-map (kbd  "M-f")
  (lambda ()
    (interactive)
    (forward-word)
    (forward-word)
    (backward-word)))

This is a rudimentary version of https://emacs.stackexchange.com/a/4272/508 that doesn't cover some cases, but easier to comprehend.


text:
Reading mailing list archives in Emacs?
I sometimes want to read mailing list archives for projects that I'm not subscribed to.  There are nice HTML archives online (e.g. https://lists.gnu.org/archive/html/emacs-devel/2014-12/msg00347.html), but I don't enjoy reading mails in the browser.
Is there an interface for Emacs to read mailing list archives?  I already use mu4e to read my personal email inside of Emacs, but I'd also like to be able to read other people's email in Emacs (to the extend that these other people have posted to public mailing lists).
There's got to be a mode for that.  (I suspect gnus is the answer, but I have never used it.)

Sure GNUS is an answer. From emacswiki
M-x gnus
B
nntp
news.gmane.io

And select gmane.emacs.devel. From here you can browse through the threads using GNUs NNTP interface (which is what it was originally written to do). This is probably the best solution for browsing through historical mailing lists.
As others have mentioned you may only want to read a small set of emails perhaps attached to a bug or patchwork. In this case if you can download the mbox file you can browse it directly without dealing with network latency. Again Emacs has many solutions for email however built in you can use Rmail quite easily. The steps for this are:
M-x rmail

This will bring up your default inbox (most likely your systems /var/mail/$USER and copy it in ~/RMAIL). However to load in a "foreign" mail box you type:
i
path/to/mbox
h

This will put you at the summary view of the mail box which you can then browse with the usual Emacs navigation.

news.gmane.org had moved to news.gmane.io. See https://lars.ingebrigtsen.no/2020/01/15/news-gmane-org-is-now-news-gmane-io/

And if you specifically want to read a thread for a certain Emacs bug, press M-x gnus-read-ephemeral-emacs-bug-group RET 12345, where 12345 is the bug number.

There's also debbugs mode for reading bug reports/threads.

Yup. But it's not as helpful when you already know the bug number.

Well, I use debbugs-gnu-bugs for that, which prompts me for bug ids.

Ok, thanks for the tip. It's indeed a bit easier to do.

stsquad's answer is good.  But there is another useful way, too.  A while back I wanted to read the Debian bug about the systemd decision by the TC in Emacs.  The GMANE interface to the bugs mailing list works, but it was easier to just download the mbox file from the bug report and open that file in gnus; that way it was all stored locally, which avoids the latency of requesting each article individually from the NNTP server.
So if there's a way to download an mbox file archive of the list you want to read, that might work for you.

Could you elaborate on your answer in more detail?  In particular, could you explain the steps needed to do this?

@Dan: I've expanded my answer to include an example for a local mbox.


text:
Fontify a region of a buffer with another major mode
I have a buffer that shows documentation for Ansible modules.  This buffer has its own major mode which provides all the standard stuff.  Notably, it fontifies the buffer to highlight inline markup, options, sections, etc.  All in all, it is pretty similar to M-x man.
At the bottom of the documentation there are usually some code examples in YAML.  I'd like to fontify these as well.  I could add my own font lock keywords for YAML, of course, but I'd rather prefer to re-use the fontification of YAML Mode.
How can I do that?  Specifically, how can I use a different major mode to fontify a particular region of a buffer?
Note that YAML Mode doesn't need to be active in this region.  The whole buffer is only a passive display buffer, and not intended to be edited.  I really only need the fontification produced as if YAML Mode were active in that region.
I presume I could copy the region of the buffer to a temporary buffer, enable YAML Mode, fontify the buffer, and the copy all text properties over.  Would that work?  If so, how do I copy text properties, and what are the relevant properties to copy?  Or is there a better approach?

How is the non-yaml fontification implemented? Do you apply text properties manually, or do you use font-lock-mode?

The links in this post sum-up at least a good chunk of the options out there: http://www.wisdomandwonder.com/link/8610/lightweight-multiple-modes-for-semi-literate-programming

I recently came across similar problem, I basically wanted to fontify code snippets in the documentation which I got some other source. I followed the approach mentioned towards the end of your answer and it worked fine for me. The function I ended up with some thing like the following
(defun my-fontify-yaml (text)
  (with-temp-buffer
    (erase-buffer)
    (insert text)
    (delay-mode-hooks (yaml-mode))
    (font-lock-default-function 'yaml-mode)
    (font-lock-default-fontify-region (point-min)
                                      (point-max)
                                      nil)
    (buffer-string)))

As @Malabarba pointed out in comments the simple approach above does not work if destination buffer uses font-lock-mode. However we can trick font-lock-mode into believing that the string is already font locked by setting the text property font-lock-face to the face, (we get the face property set, when we use the function above) and setting text-property fontified to t. The following function takes a string returned by the function above and does the required processing so that the string is inserted fontified (this is taken from org-mode's org-src-font-lock-fontify-block function
(defun my-fontify-using-faces (text)
  (let ((pos 0))
    (while (setq next (next-single-property-change pos 'face text))
      (put-text-property pos next 'font-lock-face (get-text-property pos 'face text) text)
      (setq pos next))
    (add-text-properties 0  (length text) '(fontified t) text)
    text))

Now you can use it as follows
(insert (my-fontify-using-faces (my-fontify-yaml "application: test\nversion: 1")))

This is the same solution I found for sx.el, but it's important to note it will only work if the destination buffer doesn't use font-lock-mode.

Right! I just realized this worked for me because I used in buffer where font-lock was not used (Help buffer)

@Malabarba found a way to make this work with destination buffers with font-lock-mode enabled

Many thanks, works perfectly!

Oh nice! Glad I could help :)

Library Narrow Indirect (narrow-indirect) can help here -- have a look at the header commentary.  It relies on:

narrowing, which limit editing to a portion on a buffer, and
indirect buffers, which copy a buffer in another one for which you can change the major mode.

Note that narrowing is disabled by default because it is considered beginner-unfriendly (the default binding is C-x n n).  You can enable it by putting the following in your init file:
(put 'narrow-to-region 'disabled nil)

You can also look at for my handmade myfn-narrow-indirect in my conf.

Does narrowing actually affect font lock, i.e. keep it away from outside of the narrowed region?  Does font lock really never remove buffer restrictions?

And anyway, a wiki package is not an option.

Besides, you don't need to remove the disabled property from a command to call it from Emacs Lisp.  It only affects interactive use.

I would suggest looking at org-src-font-lock-fontify-block which provides this functionality for org-mode source blocks. It seems to just copy the relevant parts to another buffer, enable the major mode there, and then copy the fontified text back. Hackish, but it seems to work.

This answer looks more like a comment insofar as it provides a suggested direction to deal with the problem, but not a complete answer.  Please consider changing it to a comment.


text:
Emacs indent with tabs to 2 columns
Current with C, Javascript, Ruby, etc. when inserting a block with { <RETURN>, Emacs automatically indents the next line, but it does so with spaces. How do I change this behavior to tab characters? The follow is my configuration.
(setq-default tab-width 2)
(setq-default c-basic-offset 2)
(setq-default indent-tabs-mode t)

This sets the indention level to 2 (for C and Ruby, but strangely 4 for Javascript), but it still inserts spaces rather than tabs.

@lawlist Okay, thanks for the advice. I'll vote to move this to emacs.stackexange.com.

@lawlist If we drive all Emacs questions away, we'll never have people answering them either. That's not a good long-term solution to that problem. Emacs as computer software is absolutely on topic here. In fact, migrating to Beta sites is typically not done, as these sites should grow organically, and not be fed by pulling questions off other sites where they would've been equally on topic.

I migrated this one as an exception for now, but let's not make this the default procedure. In fact, @lawlist, when mentioning other sites, you should at least mention that the question should not be just posted there again, but rather that the OP should flag it for migration if they didn't get an answer within, say, two days.

I'm guessing you have something overriding the default values either later in your init file or in a mode hook.

Use C-h v indent-tabs-mode from one of the buffers in question to check its actual value in that buffer. As Dan says, presumably some other config is overriding your default.

The Ruby editing mode defines ruby-indent-tabs-mode and sets indent-tabs-mode to that value when the mode is invoked.  The default for this is nil.  To fix your problem, set this variable instead.
This seems like a bug to me.  There's no reason Ruby needs its own special setting for this.
Note also that c-basic-offset doesn't affect Ruby.  Ruby has ruby-indent-level.  It's a bit of an Emacs oddity that modes must provide their own variables for basic indentation.


text:
Keep ERC buffers in the background on reconnect
I'm using ERC (with ZNC) as my IRC client.  I'm joined to quite a few channels and when I run znc-all all my buffers are restored and the logs are replayed.  This is all great.
What I find very annoying, however, is that while replaying the logs each channel buffer is popped to the front and I really can't do any other work at that time.
It's even more annoying when I'm reconnecting automatically after being temporarily disconnected.  All of a sudden my work is interrupted by these channel buffers that pop to the front while the channel logs are replayed.
How can I tell ERC/ZNC to keep the buffers in the background when replaying chat logs?  I don't want Emacs to ever switch buffers unless I explicitly ask it to switch buffers.

What about using dedicated window?

I don't want to dedicate any window to any of the many buffers I have open, just to prevent ERC from popping its own buffers.  I have never used dedicated windows, though.  Could you expand on how this can be used to stop ERC from popping buffers without having to mark each of the buffers I could possibly visit as dedicated?

"without having to mark each of the buffers I could possibly visit as dedicated"? No I can't, I was thinking about mark some windows as dedicated & when inside those windows, no other buffer will popup

I'm not sure I completely understand the question. Is it that the function znc-all sometimes runs automatically and takes you off whatever you're working on? Could you write a different function which runs automatically which doesn't switch the window?

I connect to ZNC on my server at the beginning of my session with znc-all.  After connecting, all channel buffers are replayed.  Emacs switches from buffer to buffer until the logs for each channel have been replayed.  This is (barely) acceptable behaviour when the session starts.  It's very annoying, however, when the ZNC connection was interrupted and Emacs reconnects automatically (how? I don't know).

(setq erc-join-buffer 'bury)

erc-join-buffer is a variable defined in `erc.el'.
Its value is bury
PDocumentation:
Determines how to display a newly created IRC buffer.

The available choices are:

  'window          - in another window,
  'window-noselect - in another window, but don't select that one,
  'frame           - in another frame,
  'bury            - bury it in a new buffer,
  'buffer          - in place of the current buffer,
  any other value  - in place of the current buffer.

Thank you, that's exactly what I was looking for and could not find!

Won't this also bury query buffers? I'd see that as a problem, I wouldn't see new private conversations!

It does also bury query buffers, yes. I use erc-track though, so anytime someone queries me, I see a tiny letter in the modeline and hit my keybinding for erc-track-switch-buffer as soon as my colleague has stopped peeking over my shoulder. After a while I've come to prefer that over having a big window pop up full of private information.


text:
How to prevent slow-down when an inferior processes generates long lines?
I use Emacs with Geiser to hack on some Scheme code.  As I'm playing around in the REPL I sometimes evaluate expressions that result in a lot of output, often all on one line.
For example, I just played with SRFI-41 (streams) and created a character stream from a big file; then I forced the stream and Geiser barfed the whole contents of the file as a character stream into my buffer.  Almost immediately, Emacs ground to a halt as more and more characters where appended to the output line, and no matter how long I kept pressing C-g or C-c C-c I could not make Emacs (or Geiser) stop.
This broke my whole Emacs session as Emacs now completely ignores my input, thinking that it needs to give priority to printing this massive character stream all on one line into an unresponsive Geiser REPL buffer.
Is there something I can do to protect my Emacs session from my destructive curiosity?  (Why does Emacs get so slow when displaying very long lines anyway?)  Can I set a limit for long lines and tell Emacs that it's okay to simply not attempt to display very long lines?

possible duplicate of How do I handle files with extremely long lines?

Well, my question is not about displaying long lines per se; I want to know how I can avoid this kind of thing in the first place (Emacs reads the line from an inferiour process, it's not read from a file I could fix); and it's about how I can prevent losing my Emacs session to Emacs's dedication to a single dynamic buffer.

"Well, my question is not about displaying long lines" Then maybe you should change your title. Perhaps you want to filter the inferior process output and add new line after a certain amount of characters?

Really though, this has little to do with long lines. yes in an ansi-term for instance has a similar (but not that horrible) effect. Really it's just the volume of text that gives emacs pause.

Text insertion in a buffer is pretty fast, it's the redisplay operations that make it appear slower than it actually is.  To be honest, running yes in a VTE terminal emulator maxes out all of my CPU cores, so I'd not use it as example.

As already answered in the comments, Emacs becoming very slow in its
redisplay for long lines is a well-known
issue.  Fixing it
would be very nice, but needs lots of thought to be pulled off
correctly.  I have an idea of how it could be accomplished based on
section 6.3 of this
document
(basically, store visual line information in the current buffer and
update it on insertion of whitespace, display properties, window
changes, etc., then use that information in the redisplay code to
avoid scanning for it all the time), but am not familiar enough with
the C internals to pull it off.
There are workarounds though.  The most obvious ones would be tuning
display-related parameters (like, enabling visual line truncation in
the graphical Emacs instance, using a non-graphical Emacs to have that
done automatically, disabling Bidi features, etc.) and preprocessing
the file contents you're reading in.  A less obvious one is
automatically post-processing the files, be it by actually truncating
their lines or adding text properties that make the lines appear
shorter than they actually are.  To turn this into a more interesting
answer, I'll present a pretty ugly hack of the former option that will
only work for comint-derived modes:
(defun my-comint-shorten-long-lines (text)
  (let* ((regexp "^\\(.\\{80\\}\\).*?$")
         (shortened-text (replace-regexp-in-string regexp "\\1" text)))
    (if (string= shortened-text text)
        text
      (propertize shortened-text 'help-echo text))))

(add-hook 'comint-preoutput-filter-functions 'my-comint-shorten-long-lines)

This defines my-comint-shorten-long-lines, a function that takes a
string possibly consisting of many lines and uses the power of regular
expressions to replace any line in it with a length of 80 characters
or more with a shortened version that displays the original text when
hovering over it.  When used as hook in
comint-preoutput-filter-functions it will filter all comint output
before it's displayed.
However, this rendition of the hack has a pretty serious weakness.  In
modes that have basic fontification going on (like, M-x ielm), it
will happily cut off lines that are part of a string and will that way
fontify everything until the next quote as string!  That's not what we
want and can be fixed with a bit more regex mastery (but will
presumably break inside a REPL for a language like Python).
While we're at it, let's highlight shortened output, too:
(defun my-comint-shorten-long-lines (text)
  (let* ((regexp "^\\(.\\{80\\}\\).*?\\(\"?\\)$")
         (shortened-text (replace-regexp-in-string regexp "\\1\\2" text)))
    (if (string= shortened-text text)
        text
      (propertize shortened-text 'font-lock-face 'shadow 'help-echo text))))

(add-hook 'comint-preoutput-filter-functions 'my-comint-shorten-long-lines)

That's a bit better, but still ugly.  Hovering on the output of
something like find / in M-x shell is not appealing (we'd ideally
want only to display the unshortened line, not all output), string
detection is rudimentary at best and truncation could be indicated
better with ellipses instead of fontifying everything.  On top of
that, it's not even guaranteed that the text coming in isn't turned
into batches.  All of this screams for doing the processing step in a
temporary buffer, but will be left for the reader as exercise (or the
author as potential blog post).

As this happened with Python likewise, solution at python-mode.el, https://launchpad.net/python-mode, is to connect to process directly, not via comint-mode.
Relies on start-process and process-send-string
For example see functions py--start-fast-process and py--fast-send-string-intern


text:
Save lock-files to a directory instead of disabling them
Emacs 24 introduced the ability to disable the creation of the infamous .#file-name lock  files.
Evaluating the following lisp form will completely disable Emacs ability to lock files to prevent concurrent changes.
Is there a way to set Emacs to save lock files in a dedicated directory, similarly to what happens with auto-save and backup files?
(setq create-lockfiles nil)

I'm afraid this is not straightforward to do considering F1 v create-lockfiles takes you to filelock.c which only exposes this variable and temporary-file-directory. So, to have this behaviour you'd either need to replace nearly all functions exposed in that file with your own Emacs Lisp functions or hand in a bug via M-x report-emacs-bug and hope for the best.

I submitted a bug report at https://debbugs.gnu.org/cgi/bugreport.cgi?bug=31908.

Definitely helps. Webpack keeps failing because of these lock files.

Submit a bug report for webpack?  (Why would it think these were files of interest?)

Emacs-28 can now put lock-files in different locations, see lock-file-name-transforms


text:
Stray trailing 4m before prompt with Zsh in M-x ansi-term
I recently read Running Shells in Emacs, and spend some time to adapt my elaborate Zsh prompt to work with the limited capabilities of M-x shell and M-x ansi-term.
Following this effort I'm now finally able to use Zsh from within Emacs, however there is an—albeit minor—nuisance with M-x ansi-term.  I always see the stray text 4m before the prompt.

As you can see, this phenomenon seems to be independent of the actual prompt theme.  It also appears with any of the built-in prompts, even the simple ones that don't use any fancy control characters.  As a matter of fact, it even happens with the default prompt, i.e. if I start Zsh without my .zshrc.
Well, it's really just a minor nuisance, and I wouldn't not really mind if I weren't able to get rid of it—I mostly prefer M-x shell anyway, where this issue does not occur.
But it really annoys me that I haven't been able to find the cause of this issue, even though I really tried to debug it.  I must say, though, that my understanding of terminals is rather limited, so I might have missed the very obvious.
I'm on OS X 10.10.  My Emacs is 25.0.50, build straight from trunk with Homebrew, and no special flags.  Zsh is 5.0.5, as included with Yosemite, but the issue also occurs with 5.0.7 installed via Homebrew.
Can anyone shed a light on this issue?

Try to set export TERM=xterm-256color in your .zshrc or (setq system-uses-terminfo nil).

system-user-terminfo didn't change anything.  Changing $TERM fixed the issue, but that can't be the solution, can it?  After all, it's a lie, essentially: ansi-term is no xterm, and definitely does not support 256 colours.

4m is an artifact from ANSI escape code used for defining a color e.g. \x1b[37;4m specifies a white color with 37 and underlined text with 4. I cannot reproduce your problem. My zsh is 5.0.7 and 'echo $TERM' in ansi-term gives me eterm-color, my emacs is 24.4.1. I tested also clean default version 'env HOME=~/tmp/emacstest emacs -Q' and I cannot see any problems.

@kmicu On OS X 10.10, I can consistently reproduce the issue with emacs -Q and no Zsh configuration at all.

Apparently this issue is caused by missing terminfo for eterm-color.  I managed to fix the issue by following the instructions in that answer to install an appropriate entry into the terminfo database.  Specifically:
$ tic -o ~/.terminfo /usr/local/share/emacs/25.0.50/etc/e/eterm-color.ti

I'm still not sure why that is needed at all.  term.el actually exports the $TERMINFO variable pointing to that directory, so the shell should be able to find the terminfo.  Zsh seems to ignore the directory, though…
It does look at ~/.terminfo, though, so the above command makes the terminfo entry available to Zsh.
I'd be glad if anyone could provide a better explanation or a solution that does not require manual intervention.


text:
ESS major modes keybindings do not work
I am connecting from a Windows machine to a Linux server via Putty (http://blog.harang.org/?tag=putty). There I start Emacs and open a script written in the statistical language R. When I open the file, the appropriate major mode ESS is loaded and shown to be active in the tool bar. Also when I type C-h m I get the information of the major mode and also all its keybinding. The variable major-mode has the value ess-mode.
So far, so good. The problem is: None of the keybindings associated with this major mode do work. I type one of them, nothing happens except that I get the message that this keybinding is undefined. In describe-bindings, the keybindings of the major mode are not shown. (This is also the information I get when I type C-h k with the key sequence.)
What can I do? What is going on? Is it because of the putty emulation I am using?

What is the value of major-mode? What does M-x describe-bindings say?

I am the question asker. As I cannot respond to the comments of the questions I do it here: 1. The variable major mode has value "ess-mode". 2. In describe-bindings, the keybindings of the major mode are not shown.

I'm having trouble following what's happening. Does C-h k report the key that you thought you had pressed? Could you post a screenshot after pressing C-h k and one of the major mode key bindings? Are you sure that the right window is focused?

Please provide a step-by-step recipe to reproduce the problem, starting with emacs -Q.


text:
Writing Emacs Packages in Java
I am an okay Java programmer and have very little knowledge of Emacs lisp, but I would still like to be able to write some packages for Emacs.
Is there a way or package that would allow me to write a package in Java?

You can't directly write an Emacs package in Java.  There is currently no way to extend Emacs in Java, nor is there a Java to Elisp transpiler.
It's common, though, to have Emacs run other programs to do work for it.  You could write a helper program like this in Java.  Whether this makes sense depends on what exactly you intend to do.

What I meant is if there was a package that would run Java programs.

Here's a little snippet that allows to run a single Java file:
(defun java-eval-nofocus ()
  "Run current Java file."
  (interactive)
  (save-buffer)
  (let* ((source (file-name-nondirectory buffer-file-name))
         (out (file-name-sans-extension source))
         (class (concat out ".class")))
    (setenv "CLASSPATH" default-directory)
    (shell-command (format "rm -f %s && javac %s" class source))
    (if (file-exists-p class)
        (message (shell-command-to-string (format "java %s" out)))
      (progn
        (set (make-local-variable 'compile-command)
             (format "javac %s" source))
        (command-execute 'compile)))))

You can simplify it for your purposes, for instance, assume you have
Utility.class on your CLASSPATH, that prints some useful info like
today's weather. Then to insert this info into a buffer you need:
(defun insert-weather ()
  (interactive)
  (insert
   (shell-command-to-string "java Utility")))
(global-set-key (kbd "C-c C-w") 'insert-weather)

Still, you won't be able to do anything more useful than inserting
static text unless you learn some Elisp.


text:
Where is my Emacs install?
I want to configure my Emacs install to work with Gmail and I need to find my install location to configure it.
I installed Emacs on my Mac using Homebrew. Where would the install be located it? How can I find it?
Is there any other way to configure Emacs?

First, some references:
Official manual: https://www.gnu.org/software/emacs/manual/html_node/emacs/Init-File.html
Some discussion with examples: https://superuser.com/questions/73458/where-is-emacs-file
Brief answer: M-:user-init-file will print in the minibuffer the location of the configuration file which was used when this Emacs version started. Typically, this will be ~/.emacs, ~/.emacs.el or ~/.emacs.d/init.el.
There are several mail user agents (programs to manage emails) available in Emacs. Gnus is the one that comes with Emacs built-in. You can put Gnus-specific configuration in the Emacs init file, or you can put it separately in ~/.gnus file.  I recommend reading this walk-through, if you will choose to use Gnus as your MUA: https://eschulte.github.io/emacs24-starter-kit/starter-kit-gnus.html . (This is the one I use too). A popular alternative is http://emacswiki.org/emacs/WanderLust but I wouldn't know how to set it up with GMail.

The link you provided for Wanderlust has some examples for gmail configuration.

@lawlist I didn't try them myself, so I don't want to make an impression that I know what I'm doing :) I only want to be responsible for Gnus part, if there will be follow-up questions.

You do not need the install location to configure Emacs. You do so though a init file in your home directory.
The manual can tell you all you need to know about customizing emacs using the init file (or directory)
https://www.gnu.org/software/emacs/manual/html_node/emacs/Init-File.html