text:
Any way to make git errors more prominent in Magit?
Whenever Git fails (e.g. if you try to rebase when your working tree has changes), Magit writes the following message:

Git failed ... [See buffer *magit-process: ... for details]

which is then immediately obscured with other stuff like

Reverting (up to) 670 file-visiting buffer(s)...

In other words it is extremely non-obvious when and why something fails, especially if you don't watch it closely, e.g. commit and switch to a different desktop, for example.
Is there any way to make Magit bark hard when Git underneath it fails, e.g. pop some buffer?

Edit: The last error messages is now also shown in the status buffer. You'll know it when you see it. But it is only shown in the status buffer - if that buffer is not visible, then the message can only be seen in the echo area. So everything said below about how to make sure you get to see the message there, still applies.
Also note that the message is only shown in the status buffer until that is refreshed.

When a git process exits with a non-zero exit status, then magit tries to find an error message in git's output. So usually you should see e.g.:

Could not read from remote repository. ... [See buffer *magit-process: use-package for details]

Git failed is only used if git did not output anything resembling an error message.

But you are right, without any user configuration, these error messages are usually drowned in a see of messages about buffers being reverted. The last of these messages reads like this:

Reverting 55 file-visiting buffer(s)...done
This can be undone using `C-/' in the affected buffers
Customize behavior using `M-x customize-option RET magit-revert-buffers RET'

My hope was that this is verbose enough to annoy users sufficiently to actually bother customizing the mentioned variable. When you do that, then you will get to read its doc-string, which explains that you should set the value to silent and (to some extend) why that isn't the default:

‘usage’   Like ‘t’ but include usage information in the summary.
          This is the default so that users come here and pick
          what is right for them.

‘silent’  Revert the buffers synchronously and be quiet about it.
          This is the recommended setting, because for the other
          values the revert messages might prevent you from
          seeing other, more important, messages in the echo
          area.

So change the value to silent and you should get to see the error messages in most cases. There might be other messages which shadow the git error messages in some cases, but that's expected to be rare.

The reason we are forcing users to read the doc-string and to change the value from the actual default to the intended default, is that there is a tiny risk of data loss, when buffers are reverted without the user being aware of it. So we do revert by default (because that's very useful), but we do it very verbosely and tell the user how to undo the reverts. (And also suggest that s/he configures the variable, which is the part you missed.)
Q: When could the automatic reverts lead to data-loss?
If the buffer has unsaved changes, then Emacs won't attempt to revert; so no risk here. If the buffer is saved and that caused the file in the working tree to contain uncommitted changes, then git refuses to perform any action which would lose these changes; so no risk here. There only is a risk, if you knowingly use buffers as a staging area (without knowing about the automatic reverts by magit). For example: Make changes, save, and commit. Notice that you should for some reason not have committed. Do a hard reset to HEAD~, expecting the buffer not to be reverted. What you should do instead (as in "take full advantage of Git and the nice wrapping provided by Magit") is a soft reset, but ...
Q: So if the risk of data loss is tiny, why are you doing all that?
... not every user might realize that, so we play it safe.
Q: But...?!
See https://github.com/magit/magit/issues/1809.

Thanks for adding the status buffer notification, tarsius. I was very happy the first time I saw that appear :)

I believe I have an answer to this part of the question:

Is there any way to make Magit bark hard when Git underneath it fails, e.g. pop some buffer?

This snippet makes the process buffer open after a git error:
  (defun auto-display-magit-process-buffer (&rest args)
    "Automatically display the process buffer when it is updated."
    (let ((magit-display-buffer-noselect t))
      (magit-process-buffer)))

  (advice-add 'magit-process-set-mode-line-error-status :before
    #'auto-display-magit-process-buffer)

I modfied a snippet I found on the Tips and Tricks section of the magit wiki: Automatically displaying the process buffer.
The original snippet opens the process buffer whenever it is written to, regardless of error or success. For example, when you push successfully.
I changed magit-process-insert-section to magit-process-set-mode-line-error-status.
This solved my specific problem: from time to time I push and that push takes a while and then fails. In the mean time I look somewhere else and miss the error.


text:
Unable to Send Commands to Omxplayer from Dired
When opening a video file with Omxplayer through dired using dired-do-shell-command, I am unable to send commands to the external program to, for example, pause the video. The file plays fine but all keyboard input gets sent to the buffer from which the file was launched.
This occurs on my Raspberry Pi running Arch Linux ARM on a TTY. Does anyone have an idea of what I can do to curb this behavior and force Emacs to allow other programs to accept keyboard input?
EDIT: To get to my issue, I've ran emacs -q then C-x d to open the directory containing a video file. While the file is at point in dired, run dired-do-shell-command (with ! if you'd like) and type omxplayer RET. The video plays as normal over Emacs and I expect to be able to pause the video with SPC or seek with <right> and <left> but instead of going to Omxplayer, those commands runs in dired. I'm not sure what else to try. The same process works fine in the Vim File Manager (vifm). It seems Emacs is running the shell command asyncronously even though I've specified for it not too.

You do not say what you've already tried. Please provide more info - perhaps a step-by-step recipe of what you do, including what you see and what you expected to see instead. That will help others help you.

Hi Drew, I've added some more details. I hope it helps with understanding the sitatuation I'm trying to describe. Please let me know if I can clarify anything else.

source: Stack Exchange

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

sort: votes


text:
Orgmode: agenda for headlines without any tag
Having 'org-agenda-files' set, is there a way to display headlines, which does not have any tags?
E.g 'C-c a' runs 'org-agenda', and then 'M' gives TODO items with specified tag. What if I want TODOs, which does not have any?

You can use a regular expression in a tags search.  A tag search for {.*} will match any tag and conversely, -{.*} will no tag.

Thanks, this method works and does not ignore tag inheritance.

For anyone searching for how to add a custom agenda command to find these: ("u" "Uncategorized" ((tags-todo "-{.*}")))

You can do a regexp search on headlines not ending in a colon:
C-c a m will prompt for a match query. Type -{:$} to match headlines not ending in colon. The regular expression goes inside the curly brackets, and the minus sign is for negating the match.
Note that this method ignores tag inheritance.

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


text:
emacs svn tex file in mac os x
I am using emacs for editing *.tex file. Tex file is controlled under svn.
I recently migrated to new macbook 12" with sub-c.
When I launch emacs from the shell, I do not have any problem in manipulating the tex file. When I launch the emacs clicking the icon in the launch bar, there occur two issue in manipulating the same tex file. They are executing the same emacs binary.
First, when the emacs is launched through icon click, the svn check-in fails. It says
    svn: E155021: This client is too old to work with the working copy at
    '/Users/...' (format 31).
    You need to get a newer Subversion client. For more details, see
     http://subversion.apache.org/faq.html#working-copy-format-change
Second, in shell launched emacs, emacs shows the version number of the tex file in the bottom of its window. When the emacs is launched from the icon clock, i do not see any version number of the tex document.
I think the both issues are rooted at the same reason. I am just wondering if
I could get some clue.

Sounds like you might have two versions of Subversion client installed. One is somehow available to the shell started by your user (maybe it is mentioned in your Bash profile?) and another available to the rest of the users. When GUI Emacs starts, it doesn't execute your Bash profile, and this would explain the difference.

I think @wvxvw is right: the Mac OS X built-in svn (/usr/bin/svn) is very old and GUI Emacs will usually use it because unlike starting Emacs from shell, GUI Emacs doesn't know your PATH. this package (https://github.com/purcell/exec-path-from-shell) is made to solve this problem.


text:
Trace Evil-mode commands
At the moment, I only know one way to determine which Emacs functions are called by any given Evil command (e.g. a sequence of key bindings in the Normal state): read the Evil source code.
Is there a more reliable and efficient way, and if so, what is it? For example, does Evil (or Emacs) have a mechanism that allows the user to tell Emacs:

"When I enter my next command, show me afterwards which Emacs functions it mapped to."

How is this different from F1 k?

I.e. Emacs's describe-key command? Similar idea, only I'd be grateful for something more Evil-aware. In Evil's Normal state, I might type, for example, vip to select the current paragraph. If I type F1kvip, the describe-key command kicks in after the v, and describes only that ("v runs the command evil-visual-char"), which means the succeeding ip results in switching to Insert state and inserting the character 'p' at that point in the buffer. This means that I still do not know which command/function vip calls, and I also have to undo the accidental insertion :)

As far as Evil is concerned, v is a standalone command, same goes for ip in its visual state map (ip in normal state map is a different story...).  The behaviour of F1 k mirrors this, so nothing unusual going on.

@wasamasa, good point, thanks. I guess that using describe-key to trace the command components piecemeal is probably the best way to go after all. If you post that as an answer, I will accept and upvote it :)

Well, I'm not entirely happy with this as answer because there are actually ways of tracing the last commands (as opposed to keystrokes) which could be more helpful in special cases, such as daw.

@wasamasa, if you have a better answer in mind, by all means post it. Thanks again!


text:
How do I protect command output in eshell and REPL buffers?
Since command outputs are easily mutable, I have to be careful when I work with eshell and REPL buffers.
Is there a way to protect them?

could you let know if Tobias' answer statisied you?

I was waiting for a more complete answer, but his answer works for eshell. Since no other answer was coming, I chose his answer.

Do you mean the lisp-scratch buffer by repl buffer?

@Tobias In my case, it is REPL buffers launched by cider-jack-in and nodejs-repl. But, I want everything except the current input line on all REPL buffers and all shell buffers to be immutable against keyboard inputs.

nodejs-repl is derived from comint-mode -- as it should be. Therefore, the added section on comint in the already existing answer should work. It looks like this is not the case for cider because cider is not based on comint but they do their own stuff for process communication.

Modes that communicate with external shells should inherit from comint mode. eshell is an exception w.r.t this principle since it emulates almost all commands on elisp-base. First, setting output read-only is described for eshell afterwards for comint-based modes.
eshell
The following lisp snippet demonstrates the usage of eshell-output-filter-functions for setting the output read-only.
It is not very sophisticated and not thoroughly tested.
(defun eshell-interactive-output-readonly ()
  "Make output of interactive commands in eshell read-only.
This should be the last entry in eshell-output-filter-functions!"
  (let ((end eshell-last-output-end))
    (save-excursion
      (goto-char end)
      (end-of-line 0)
      (setq end (point)))
    (when (< eshell-last-output-block-begin end)
      (put-text-property eshell-last-output-block-begin end 'read-only "Read-only interactive eshell output"))))

(defun eshell-make-interactive-output-readonly ()
  (add-hook 'eshell-output-filter-functions 'eshell-interactive-output-readonly 'append))

(add-hook 'eshell-mode-hook 'eshell-make-interactive-output-readonly)

comint based modes:
It looks like one cannot use comint-output-filter-functions for setting the command output read-only in comint-based modes.
The reason is that comint-output-filter sets unconditionally the rear-nonsticky text property to t. Therefore you can insert text into the output despite of the read-only-property even if already existing output characters cannot be modified.
The only chance to protect the output is an after-advice for comint-output-filter. The following code-snippet demonstrates the principle.
(defadvice comint-output-filter (after output-readonly activate)
  "Set last process output read-only."
  (add-text-properties comint-last-output-start (line-end-position 0)
               '(read-only "Process output is read-only."
                   rear-nonsticky (inhibit-line-move-field-capture))))

Notably, a lot of these modes fail to take advantage of the fields feature of Emacs. For example, if I was writing eshell, I would propertize the prompt with 'field 'prompt, the user-typed input with 'field 'input, and command output with 'field 'output. This wouldn't be perfect in the edge cases (an interactive external command which prompts for its own input wouldn't get detected by eshell, for example), but it's far better than no fields at all. Even something as little as tagging the prompt with a field is huge.

The relevant tie-in to this answer is that if these modes actually annotated the different pieces of text, then the solution to marking pieces read-only becomes more elegant - more universally reusable and composable - because then we could scan the text for the relevant field properties, reducing the mode-specific logic. And incidentally, for example in eshell at least, we can inject a field property to the prompt and add field to its rear-nonsticky property, by overriding eshell-prompt-function (and disabling the default prompt highlighting) or advising eshell-emit-prompt.


text:
How to display plain text attachments inline with mu4e?
I'm using mu4e as my email client and it works fine for the most part.  However, I'm working with patches sent via email very often and mu4e won't display inlined attachments as part of the email body, which is very inconvenient.  Instead it lists them as attachments that I can awkwardly open in Emacs with a little too many steps.
Is there a way to let mu4e display certain attachments inline with the email text?
(I would also like attachments of type text/plain or text/x-patch to be displayed inline, even when their Content-Disposition is attachment, but that's optional.)
It is especially annoying when I get an email with an embedded short patch snippet, with the body text continuing afterward.  The snippet is cut out of context and having to do A-e 2 RET is taking me out of the email.

Assuming that this can't simply be enabled with a (setq ...) or something similarly easy, would you consider a feature request to the maintainer?

An issue is now reported: https://github.com/djcb/mu/issues/942

Is there a way to let mu4e display certain attachments inline with the email text?

The short answer is "no."
mu concatenates all text/plain parts to form the body of a message--- both for indexing and viewing messages. As far as I can tell only text/plain gets this treatment and since this is done by mu you cannot change this behavior in mu4e. (See static void accumulate_text_part (MuMsg *msg, MuMsgPart *part, GString **gstrp) for the code.)
The location of a part with Content-Disposition: inline is lost when mu accumulates text parts to build a message body, and so one cannot display any part (except for text/plain) truely inline.
It should be possible to display text/plain, text/x-patch, or any other attachment at the end of the body similar to the way mu4e displays images when mu4e-view-show-images is set to t. (This would require writing a bit of elisp to extend mu4e. I think I know how to do it, so let me know if you're interested.)
I learned all this by reading the mu source code. Please do correct me if I'm wrong.

Not completely sure if this is what you're looking for, but I open attachments in emacs with A-e from inside the message.
More info: http://www.djcbsoftware.nl/code/mu/mu4e/MSGV-Actions.html

no, that's not what I meant.  I do that too now, but I find it awkward.  I really want plain text attachments to be displayed inline.  It's especially annoying when the body text continues after the plain text attachment.  Right now the attachment is just cut from the body.


text:
Obtain absolute pixel position of point
I'd like to obtain the absolute pixel position of the point (i.e. the cursor, not the mouse pointer) in the current buffer in a GUI frame, to pass it onwards to an external program.
I don't mind where the pixel position is anchored, e.g. whether to the frame or to the display, as I can easily convert between these, but I haven't found a way to obtain either position within Emacs.
What did I miss?  What function can I use to get the pixel position of the point?

You can use window-absolute-pixel-position:

window-absolute-pixel-position is a compiled Lisp function in
  `window.el'.
(window-absolute-pixel-position &optional POSITION WINDOW)
Return display coordinates of POSITION in WINDOW.
  If the buffer position POSITION is visible in window WINDOW,
  return the display coordinates of the upper/left corner of the
  glyph at POSITION.  The return value is a cons of the X- and
  Y-coordinates of that corner, relative to an origin at (0, 0) of
  WINDOW's display.  Return nil if POSITION is not visible in
  WINDOW.
WINDOW must be a live window and defaults to the selected window.
  POSITION defaults to the value of `window-point' of WINDOW.


text:
setting comment face in major mode on multi-line word-delimited comments
I am working on a major mode for an input file format I am interested in and want to set multi-line comments with the delimiters skip and noskip like
skip larb noskip

or
skip
GRID
  TYPE structured
  NXYZ 284 307 1
END
noskip

Using the re-builder, I came upon the following regex that highlights both single and multi-line comments
"skip\\(.\\|\n\\)*?noskip"

But this doesn't work to pass to the font-lock-comment-face. Only the single-line version gets its font-locked.
Is there a mode with word-delimited multi-line comments like I  want, that I can borrow the right syntax from?

Rather than handle it in font-lock highlighing rules, you want to handle it at the level of syntax tables.  Now syntax-tables can't directly handle such start/end markers, so you'll have to use the syntax-propertize system.  E.g.
(setq-local syntax-propertize-function
  (syntax-propertize-rules
    ("\\_<\\(s\\)kip\\_>" (1 "<"))
    ("\\_<noski\\(p\\)\\_>" (1 ">"))))

An important difference between font-lock rules and syntax-propertize rules is that font-lock rules can be applied "out of order" or piecemeal.  More specifically, by default Emacs only applies font-lock rules to the parts of the buffer that are displayed, so if the skip in your code happens to be in a part of the buffer which was never displayed, the font-lock rules will simply miss it.
Another important difference is that font-lock rules don't naturally have state, so you either need to use one regexp which matches the multi-line element (and then try and force font-lock to always consider a large enough chunk of the buffer to see both skip and noskip at the same time) or to separately match skip, noskip, and every line between them, and to each time check whether we're still within a skip..noskip thingy.

Maybe say why Kris wants to handle it this way rather than that way.


text:
Org-src-fontify-natively makes Magit think there are unsaved files
I've got a weird one for you. When all of the following are true:

I'm using org-mode
My org-mode file has a code block
I export the org file
org-src-fontify-natively is true

Then I get a leftover buffer with a name like " org-src-fontification:clojure-mode". It's considered an "invisible" buffer, so it only shows up when listing buffers from Elisp code. It does not appear in the interactive buffer list.
The next time I refresh my magit-status, I get prompted to save a file. There's no option to skip it! If I save the file, it has the contents of the leftover internal buffer.
If I turn off org-src-fontify-natively then this doesn't happen. But my exports also don't get nice fontification either.
Is there some way to either discard that buffer, or convince magit to ignore it?

Does C-x s instead of magit-status cause the same prompt?

@npostavs Yes it does.

One workaround is to advise the functions involved. For example, you could add :after advice to org-src-font-lock-fontify-block to kill the buffer it creates, perhaps like this:
(defun kill-org-src-buffers (&rest args)
  "Kill temporary buffers created by
org-src-font-lock-fontify-block so they don't interfere with
magit-mode."
  (dolist (b (buffer-list))
    (let ((bufname (buffer-name b)))
      (if (string-prefix-p " org-src-fontification:" bufname)
          (kill-buffer b)))))

(advice-add 'org-src-font-lock-fontify-block
            :after #'kill-org-src-buffers)

The kill-org-src-buffers iterates over all buffers, killing any that match the buffer name prefix that org-src-font-lock-fontify-block uses for its "temporary" buffers. Alternatively, advising magit-save-repository-buffers with :before advice that takes a similar approach would likely work too.
I think it's a bug that org-src-font-lock-fontify-block creates a buffer using get-buffer-create to do work that appears to require only a temporary buffer; it should use with-temp-buffer instead.

I think the actual bug is that the "temporary" buffer ends up visiting a file (I guess they're purposely reusing the buffer for efficiency).

Would you consider filing a bug? It sounds like the solution wouldn't be too challenging.

@PythonNut: normally, yes, I'd submit a patch, especially when the solution is as easy as what's required here: a 3-line change to use with-temp-buffer instead of with-current-buffer and get-buffer-create. But in this case, I'm not an actual user of either org-mode or magit-mode. To report an org-mode bug it appears I'd have to sign up to their mailing list, learn their requirements for how to format the bug report just so they'd even consider it, and actually run org-mode and magit-mode to get the details needed for the report.


text:
Emacs does not contain package "package"
I want to add C auto-completion at least so that I can use Emacs on a regular basis as my C editor. I am new to Emacs, and I had already it installed in my system, because it came with the OS (I think). It's version is  22.1.1.
I'm trying to follow the following tutorial:

https://www.youtube.com/watch?v=HTUE03LnaXA

To add auto-completion to Emacs, and we started by adding the following code to the ~/.emacs file:
; start package.el with emacs
(require 'package)
; add MELPA to repository list
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/"))
; initialize package.el
(package-initialize)

But when I save the file ~/.emacs and start Emacs again, I get the following message:

An error has occurred while loading `/Users/cell/.emacs':
File error: Cannot open load file, package
To ensure normal operation, you should investigate and remove the
  cause of the error in your initialization file.  Start Emacs with the
  `--debug-init' option to view a complete error backtrace.
Loading find-func...done find-library-name: Can't find library package

I don't know anything about Lisp, but from my understanding the problem is that the package called 'package does not exist. Indeed if I try to search it with
M-x find-library

and then I type package, it tells me:

Can't find library package

According to this answer:

https://stackoverflow.com/questions/20105967/emacs-marmalade-cannot-open-load-file-package

It might be that my Emacs does not have package. How can I solve this, and mostly, how can I add auto-completion to C programs?
Note: I would prefer to stick with this version of Emacs terminal since it came with the OS, apparently. I've also installed another Emacs using a .dmg file, but I would like to work on the terminal also (or mostly).

If you are on OSX I don't think Emacs would have come preinstalled (though I could be wrong). I also don't know if your issue is caused by having an older version - but your version is quite old. I know you don't want to update, but I think you will run into more issues than this if you do not.

@elethan OS X includes GNU Emacs 22, the last version released under GPL 2.

@lunaryorn thanks for the info! I was assuming that since it doesn't come pre-packaged with most Linux distributions that it wouldn't come packaged with OS X.

OS-X comes with emacs 22, which is several years out of date. One easy way to get a current emacs is by downloading from http://emacsformacosx.com/. This will give you package.

Yes, this is exactly the one I installed (apart from the one I had already). The problem is that I would like to run Emacs also from the terminal, and the command emacs is by default connected to the Emacs which comes with the OS...I know I can add the new installed Emacs to the path, but is there a way to make this new one the default one?

Adding the new emacs to the path should do the trick, just put it at the front. I've got this in my .bash_profile: export PATH=/Applications/Emacs.app/Contents/MacOS:$PATH

Yes, it did the trick, thanks! And to start it without the windowing system, I also add the following alias: alias="emacs -nw", if someone is interested.

I have a question: does the dmg-installed Emacs also refers to the ~/.emacs before initialising or does it refer to its own initial-options launching file?

The same ~/.emacs


text:
How can I quit Emacs from within a term within Emacs?
I'm in a situation where I have to ssh into a machine and do all of my coding on there. For a while I would ssh in and then use tmux and emacs -nw mode. Recently, I discovered the term command. Now instead of using tmux, I open up normal Emacs on my desktop and use term to ssh in.
Once I'm in, I run emacs -nw from within term within Emacs on my desktop. This works great, and I have all of my pretty colors. The only problem is, I can't figure out how to cleanly close the emacs -nw within the Emacs on my desktop. C-x C-c does not work, as expected.
How can I close the innermost Emacs, and get back to term? Is there a better way to edit files via ssh?

Ah. I think I've figured it out. This page has helped me a ton: https://www.gnu.org/software/emacs/manual/html_node/emacs/Exiting.html

A better way - or at least another way - is to use Tramp to edit files over ssh.

There are a few answers here.
Quitting Emacs without C-x C-c
First, you can quit emacs by running the command that C-x C-c is bound to: M-x save-buffers-kill-terminal.
Alternatives to recursive Emacs
Emacs is able to edit files on remote servers, so you don't even need to ssh into the remote server, and you won't need an Emacs inside a term inside your original Emacs. This functionality is called TRAMP, an acronym for "Transparent Remote (file) Access, Multiple Protocol". To edit a file on a remote server, run C-x C-f like normal, but instead of finding the file normally, use a special format for the file path: /user@host:path/to.file
So if you want to edit the file located at /etc/hosts on the remote server my-remote-machine, and you need to log in as gragas, find the file this way:
C-x C-f /gragas@my-remote-machine:/etc/hosts

It will prompt you for a password if one is required. It'll transparently save the file across the network, so absent a bit longer time it takes to save, you won't even notice it's a remote file.

As a complete beginner, I was confused at what C meant. Please add to your description that C is ctrl on an ordinary PC. So it is ctrl+x, pause, and ctrl+c. The esc button can break this sequence, so don't use it while quitting.

@t7e The first thing any beginner in emacs should do is run the built-in tutorial. Press and hold Contral and then press h, followed by pressing t (for tutorial). On the very first page it explains The C-x C-x style keystroke labels. This is all very commonly used in emacs.

kill $(ps -o ppid= -p $$)

Which is a bit more general: when run from terminal started from Emacs it will look for the parent process of the current process ($$ is shell's way to get the process id of the current process).  And kill it.  You could put this in your bash profile as a function or alias to make it easier to type, eg:
ekill() { kill $(ps -o ppid= -p $$) }

In your ~/.bash_profile (on remote machine), and then you'd only need to type ekill once you want to kill Emacs from inside term run by Emacs.


text:
Orgmode set font face on per file basis
is there a way to set the font attributes on per file basis? I'm surprised this is not a main feature... I don't want my todo lists to look the same as my articles or journal.
IF there is such a thing is there also something like importing? e.g. import 'article_style'?
I tried the following without success
;; Local Variables:
;; eval: '(org-level-1 ((t (:weight thin :height 1.6 :family "Helvetica Neue"))))
;; End:

I'm not surprised that it doesn't do anything, since the result of evaluating a quoted list is simply to return the list.  In other words, you have not told emacs to do anything.  You would need to wrap that statement in a call to custom-set-faces if you wanted it to do something.  However, this will change the face globally, which is obviously not what you want in this case.

Looking around, I would say that https://github.com/vic/color-theme-buffer-local might be your best bet.  You could define your own themes in your .emacs file, and then load them from the file-local variables.


text:
Why won't "fg" reopen emacs after C-z?
I open a terminal and type fg like it says but it says no current process.
I also tried %emacs and got the same.
I'm on trusty tahr 14.04, anyone else got this?
*edit: I was following the built-in tutorial.

That may not be enough information to answer the question. How did you start emacs? Is it running as a terminal application or as a gui application with a proper os window (you didn't say what OS you're using, but it wouldn't matter; in this case C-z will iconify or minimize the window as appropriate for the OS).

Works for me. Are you sure everything is working correctly? Does this work in bash and emacs -Q?

Try pkill -CONT emacs but as others have said there is not enough information to answer.

Are you running fg in the same terminal you started emacs in?

Did you start Emacs in the background, to begin with? If not then it's no wonder that fg won't move it to the foreground. Try starting Emacs using emacs & instead of just emacs, if you haven't tried that already. As others have indicated, your question is quite poor - no specific description, no recipe to reproduce the problem. Don't make people guess what you did and what you're asking. Otherwise, you likely won't get good help, and the question might be closed as unclear.

The fg job control command should work if you run from the same terminal where you entered Control-z.
To find out what processes are available to be placed in the fore ground use the jobs command. If jobs does not list your Emacs process, you're in the wrong shell.

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


text:
Help Buffer on Hover Possible?
I'm looking for something similar to Eldoc mode (hover over a function and the parameter list appears in the minibuffer), only I'd like to have a help buffer appear, as if I had just run describe-function.  Is there a minor mode that will do this?
Having the help buffer be in a separate frame would be ideal, but I can figure that out at a later point.  Funnily enough, I think I saw something like this for SLIME, but I haven't been able to find it again.

For years I've used the rgr/context-help solution from the EmacsWiki for this, with some slight tweaks. A few aspects still bothered me, though, so this question inspired me to write a new variant of that as a global minor mode. Among other differences, this utilises help-xref-interned to display all (variable, function, face) kinds of help for a symbol instead of arbitrarily choosing between describe-function and describe-variable when both cells are defined.
(define-minor-mode my-contextual-help-mode
  "Show help for the elisp symbol at point in the current *Help* buffer.

Advises `eldoc-print-current-symbol-info'."
  :lighter " C-h"
  :global t
  (require 'help-mode) ;; for `help-xref-interned'
  (when (eq this-command 'my-contextual-help-mode)
    (message "Contextual help is %s" (if my-contextual-help-mode "on" "off")))
  (and my-contextual-help-mode
       (eldoc-mode 1)
       (if (fboundp 'eldoc-current-symbol)
           (eldoc-current-symbol)
         (elisp--current-symbol))
       (my-contextual-help :force)))

(defadvice eldoc-print-current-symbol-info (before my-contextual-help activate)
  "Triggers contextual elisp *Help*. Enabled by `my-contextual-help-mode'."
  (and my-contextual-help-mode
       (derived-mode-p 'emacs-lisp-mode)
       (my-contextual-help)))

(defvar-local my-contextual-help-last-symbol nil
  ;; Using a buffer-local variable for this means that we can't
  ;; trigger changes to the help buffer simply by switching windows,
  ;; which seems generally preferable to the alternative.
  "The last symbol processed by `my-contextual-help' in this buffer.")

(defun my-contextual-help (&optional force)
  "Describe function, variable, or face at point, if *Help* buffer is visible."
  (let ((help-visible-p (get-buffer-window (help-buffer))))
    (when (or help-visible-p force)
      (let ((sym (if (fboundp 'eldoc-current-symbol)
                     (eldoc-current-symbol)
                   (elisp--current-symbol))))
        ;; We ignore keyword symbols, as their help is redundant.
        ;; If something else changes the help buffer contents, ensure we
        ;; don't immediately revert back to the current symbol's help.
        (and (not (keywordp sym))
             (or (not (eq sym my-contextual-help-last-symbol))
                 (and force (not help-visible-p)))
             (setq my-contextual-help-last-symbol sym)
             sym
             (save-selected-window
               (help-xref-interned sym)))))))

(defun my-contextual-help-toggle ()
  "Intelligently enable or disable `my-contextual-help-mode'."
  (interactive)
  (if (get-buffer-window (help-buffer))
      (my-contextual-help-mode 'toggle)
    (my-contextual-help-mode 1)))

(my-contextual-help-mode 1)

Thanks for the quick response! This is pretty close to what I was looking for.  Is there any way to make it fully replace Eldoc?  That is, not have to open a preliminary Help buffer?
It may sound somewhat annoying, but in that case I would toggle it with a keybinding or try to have a dedicated Help buffer frame that it would occupy.

Blimey I wrote that yonks ago and totally forgot. The elisp is a mess. But nice to know it was used. You have an update? This code reports (eldoc-current-symbol) doesn't exist.

Changing (eldoc-current-symbol) to  (symbol-at-point) works.

Hi @RichieHH :) Thanks for putting that code on the Wiki in the first place -- very helpful.  I'd subsequently made further changes to this in my own config, so I've updated the answer.  elisp--current-symbol is the exact same code as the old eldoc-current-symbol, so I used that for consistency.

Works well. You should replace my old beginner's junk on the wiki page with your stuff.

Sure; I've updated that page too.

FF to 2021 and I created this as an exercise in making my own minor mode and learning customisation.  It loads packages you wont need but the idea is there. https://github.com/rileyrg/el-docstring-sap

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


text:
Emacs+Python+Pygame segmentation fault (core dumped)
I am using Emacs 24.5.1 for writing something in pygame in python 2.7.11. Very often (precisely speaking every second time!) when I try to evaluate the buffer (the whole file) with C-c C-c everything crashes and in the shell I get this message:
Process Python[/path/to/the/file.py] segmentation fault (core dumped)

Why is this happening and what is the way to get rid of it?
I should also mention that this only happens when I try things in Emacs, if I run the program in terminal or other editors like geany every thing works fine. But I would like to work in Emacs on my python projects. I am using Ubuntu 16.04 LTS.

What's your python setup? Does your code run at all on evaluation, or are you just trying to load function definitions?

As said the code runs once, and the next time it crashes! It crashes 50% of the times (every second time)! I evaluate the whole file with C-c C-c.

As said, "when I try to evaluate the buffer... everything crashes." Again: what's your Emacs python configuration? Is your code available anyplace? Without more information, my best intuition is you need to change your code such that there's a discrete main method -- no code gets run on file evaluation. You should then be able to evaluate it (that is, load all the function and variable definitions in to the python process) and execute it by calling the main explicitly in that process.


text:
Replace whole words only
I want to replace all occurrences of a word in the whole buffer. What i do is:
M-x replace-string RET word-to-be-replaced RET new-word

The problem with this is that it also changes the word-to-be-replaced even if its only part of another word (for example wanting to change mod to off_mod results also changing set_mode to set_off_mode). How can i change it only in cases it exists exactly as a whole word  and not also as parts of other words?

Have a look at regular expressions.

If you provide the universal argument to replace-string, that is by pressing C-u before M-x replace-string, it only replaces matches that are surrounded by word boundaries.
So, for example, a buffer containing
mod
set_mode

would be become after C-u M-x replace-string RET mod RET off_mod
off_mod
set_mode

You can find this information by looking in the manual: C-h i (to get the info index) m Emacs RET (to open the Emacs user manual section) and finding "replace-string" through the topic index by doing i replace-string RET.
Alternatively, you could look-up the function's documentation by doing C-h f replace-string

+1, especially for teaching about the manual. Also: C-h r takes you to the Emacs manual, where i replace-string takes you directly to the doc about replace-string. i is your friend in Info.


text:
Dired: group directories and symlinks to directories first
Is there a way to make dired group directories and symlinks to directories first?
If I add --group-directories, like this:
(setq dired-listing-switches "--group-directories-first -al")

then it groups directories first, but symlinks still get sorted under files.
If I also add --dereference, like:
(setq dired-listing-switches "--group-directories-first --dereference -al")

then symlinks get resolved, and the directories do all show up together. But there's no indication anymore that they are symlinks anymore. I'd like them to be still displayed as symlinks, but get grouped first too.

Note that some ls versions do not support the --group-directories-first option.

Yes, that is what you get if you load standard library ls-lisp.el and you customize option ls-lisp-dirs-first to non-nil.
(If the value of option ls-lisp-emulation is MS-Windows then ls-lisp-dirs-first is non-nil by default.  This is the case if you use Emacs on MS Windows, but you can set it this way on any platform.)
If you also use library Dired Sort Menu then you get a S-mouse-2 popup menu in Dired (and a menu-bar menu) that provides all of the ls-lisp.el sorting possibilities.

Thanks! That does work, but ls-lisp seems to lack a "-v" flag to sort numbers naturally (ie 1 2 10 instead of 1 10 2). I guess I could hack that in, but ls-lisp is also noticeably slower, so it'd be easier to use a modified ls instead. (It does bother me in ls too, after all, so that might just be the better choice.)

Yes, ls-lisp is coded in Lisp, so it can be slower. Yes, it does not support all of the switches of all versions of ls. Remember too that you can define your own commands that call other commands, and some of those can explicitly make use of ls-lisp. IOW, you can mix and match. You need load ls-lisp only once (in any of those commands: (require 'ls-lisp). Then bind variable ls-lisp-use-insert-directory-program as needed, to get the ls behavior you want: from ls or from ls-lisp.

I gave the ls patch a try and posted that as an answer as well. Your answer is probably the better one in general because it's portable, more straightforward and directly answers the question. I would've probably just used ls-lisp as a "good enough" solution if it supported -v as well.

The ls-lisp solution is portable and straightforward, but unfortunately lacks some important (to me) flags and is considerably slower.
So instead, one can also modify ls directly. Because I wanted the same feature in ls in the terminal anyway, I wrote a patch for the ls in GNU's coreutils. That's certainly a lot less portable, but it was a much smaller and more desirable change than extending ls-lisp with the missing flags. (Still, ls-lisp can be used as a fallback as well.)
This patch for coreutils (8.25) sorts symlinked directories like directories when --group-directories-first is provided:
diff --git a/src/ls.c b/src/ls.c
index 3572060..8dd6395 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -2969,10 +2969,10 @@ gobble_file (char const *name, enum filetype type, ino_t inode,
               || is_colored (C_STICKY_OTHER_WRITABLE)))
       /* When dereferencing symlinks, the inode and type must come from
          stat, but readdir provides the inode and type of lstat.  */
-      || ((print_inode || format_needs_type)
+      || ((print_inode || format_needs_type || directories_first)
           && (type == symbolic_link || type == unknown)
           && (dereference == DEREF_ALWAYS
-              || color_symlink_as_referent || check_symlink_color))
+              || color_symlink_as_referent || check_symlink_color || directories_first))
       /* Command line dereferences are already taken care of by the above
          assertion that the inode number is not yet known.  */
       || (print_inode && inode == NOT_AN_INODE_NUMBER)
@@ -3113,7 +3113,7 @@ gobble_file (char const *name, enum filetype type, ino_t inode,
         }

       if (S_ISLNK (f->stat.st_mode)
-          && (format == long_format || check_symlink_color))
+          && (format == long_format || check_symlink_color || directories_first))
         {
           struct stat linkstats;

@@ -3123,7 +3123,7 @@ gobble_file (char const *name, enum filetype type, ino_t inode,
           /* Avoid following symbolic links when possible, ie, when
              they won't be traced and when no indicator is needed.  */
           if (linkname
-              && (file_type <= indicator_style || check_symlink_color)
+              && (file_type <= indicator_style || check_symlink_color || directories_first)
               && stat (linkname, &linkstats) == 0)
             {
               f->linkok = true;
@@ -3131,7 +3131,7 @@ gobble_file (char const *name, enum filetype type, ino_t inode,
               /* Symbolic links to directories that are mentioned on the
                  command line are automatically traced if not being
                  listed as files.  */
-              if (!command_line_arg || format == long_format
+              if (!command_line_arg || format == long_format || directories_first
                   || !S_ISDIR (linkstats.st_mode))
                 {
                   /* Get the linked-to file's mode for the filetype indicator
@@ -3251,6 +3251,15 @@ is_directory (const struct fileinfo *f)
   return f->filetype == directory || f->filetype == arg_directory;
 }

+/* Return true if F refers to a directory or a symlink pointing at a directory.  */
+static bool
+is_directory_or_symlink_to_directory (const struct fileinfo *f)
+{
+  return f->filetype == directory
+    || f->filetype == arg_directory
+    || (f->filetype == symbolic_link && S_ISDIR(f->linkmode));
+}
+
 /* Put the name of the file that FILENAME is a symbolic link to
    into the LINKNAME field of 'f'.  COMMAND_LINE_ARG indicates whether
    FILENAME is a command-line argument.  */
@@ -3396,8 +3405,8 @@ typedef int (*qsortFunc)(V a, V b);
 #define DIRFIRST_CHECK(a, b)                       \
   do                                   \
     {                                  \
-      bool a_is_dir = is_directory ((struct fileinfo const *) a);  \
-      bool b_is_dir = is_directory ((struct fileinfo const *) b);  \
+      bool a_is_dir = is_directory_or_symlink_to_directory ((struct fileinfo const *) a); \
+      bool b_is_dir = is_directory_or_symlink_to_directory ((struct fileinfo const *) b);  \
       if (a_is_dir && !b_is_dir)                   \
         return -1;         /* a goes before b */           \
       if (!a_is_dir && b_is_dir)                   \


text:
auth-password-store for ftp over tramp
When accessing remote ftp server with tramp
C-x C-f /ftp:user@host#port/
tramp asks me for password. I also use auth-password-store to store passwords in a pass-compatibale fashion, that is, host is specified in a filename of a gpg-encrypted file containing password on its first line. However, tramp (or maybe it's AngeFtp?) keeps asking for password, even though I've created a host.gpg file in my password store.

I tried symlinking ftp:user@host.gpg to the password file.
I tried symlinking host#port.gpg as well as ftp:user@host.gpg and ftp:user@host#port.gpg
auth-password-store and tramp work fine together for C-x C-f /sudo::/ command, that is, it does find the appropriate file in my password-store and requests my gpg password then
auth-password-store works fine with symlinks to genuine password files (which is to be expected, I guess?)
I tried adding protocol: ftp record to password file

How do I make tramp recognise my password-store password? Should I file an issue to tramp, or maybe to AngeFtp developers?

Tramp forwards all ftp-related requests to ange-ftp. This uses the native ftp client on your local machine.
Therefore, passwords can be stored only in ~/.netrc. I doubt that this will be changed in Emacs.

I have the following two lines in my init.el:
(setq auth-sources "~/.secrets/authinfo.gpg")
(setq ange-ftp-netrc-filename auth-sources)


text:
auto-complete-c-headers just works with C. No result with C++
I installed the auto-complete-c-headers package and added the following in my Emacs configuration file
; start auto-complete with emacs
(require 'auto-complete)
; do default config for auto-complete
(require 'auto-complete-config)
(ac-config-default)
; let's define a function which initializes auto-complete-c-headers and gets called for c/c++ hooks
(defun my:ac-c-header-init ()
(require 'auto-complete-c-headers)
  (add-to-list 'ac-sources 'ac-source-c-headers)
  (add-to-list 'achead:include-directories '"/usr/include/c++/4.8
 /usr/include/x86_64-linux-gnu/c++/4.8
 /usr/include/c++/4.8/backward
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
"))
; now let's call this funcion from c/c++ hooks
(add-hook 'c++-mode-hook 'my:ac-c-header-init)
(add-hook 'c-mode-hook 'my:ac-c-header-init)

I included the directories listed by the command gcc -xc++ -E -v -.
The autocomplete works fine with C header files, but does nothing with the C++ ones.

It looks like you are incorrectly adding the C++ headers to achead:include-directories.  Each header should be a separate item in the list, not the Heredoc-like syntax you're using.  You are prepending just one string with embedded newlines, which of course does not exist on disk.  Instead of:
(require 'auto-complete-c-headers)
  (add-to-list 'ac-sources 'ac-source-c-headers)
  (add-to-list 'achead:include-directories '"/usr/include/c++/4.8
 /usr/include/x86_64-linux-gnu/c++/4.8
 /usr/include/c++/4.8/backward
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
"))

Try this:
(require 'auto-complete-c-headers)
  (add-to-list 'ac-sources 'ac-source-c-headers)
  (setq achead:include-directories
   (append '("/usr/include/c++/4.8"
             "/usr/include/x86_64-linux-gnu/c++/4.8"
             "/usr/include/c++/4.8/backward"
             "/usr/lib/gcc/x86_64-linux-gnu/4.8/include"
             "/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed"
             "/usr/include/x86_64-linux-gnu")
             achead:include-directories)))

The C header files probably work because by default, the package adds /usr/include and /usr/local/include to achead:include-directories.

What does M-: achead:include-directories show in a c-++-mode buffer?

("/usr/include/c++/4.8" "/usr/include/x86_64-linux-gnu/c++/4.8" "/usr/include/c++/4.8/backward" "/usr/lib/gcc/x86_64-linux-gnu/4.8/include" "/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed" "/usr/include/x86_64-linux-gnu" "/usr/include/c++/4.8" "/usr/include/x86_64-linux-gnu/c++/4.8" "/usr/include/c++/4.8/backward" "/usr/lib/gcc/x86_64-linux-gnu/4.8/include" "/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed" "/usr/include/x86_64-linux-gnu" ...)

Looks OK. What doesn't work?  Pressing  in a #include <x|> (where x is some character that is a prefix to a file name that exists in one of those directories, and | represents the cursor) completes only c headers?  What does evaluating ac-sources in that buffer show?

Without reason the things started to work. I don't know what I did. That evaluate command may have solved the problem?

The evaluate command should have had no effect. Perhaps you were debugging in an intermediate state wherein all changes to the setup code had not yet propagated to your testing environment. Happens to me sometimes when I forget to evaluate the latest elisp code.


text:
Magit Status Runs Very Slowly
I installed the magit package via Marmalade. When I run M-x magit-status it takes a long time to run and complete (about 30 seconds). How can I speed this up?

The question risks being closed as too broad or unclear. Please specify exactly what you have tried.

See http://emacs.stackexchange.com/q/19440/5296; if it's only slow on first magit-status, also see http://emacs.stackexchange.com/a/19110/5296

I installed the magit package via Marmalade.

The magit package on Marmalade is no longer being updated, because the maintainer of Marmalade has stopped actually maintaining it. Before I gave up on Marmalade, I had some technical issues when trying to upload new releases and it was very hard to get the maintainer to help me.
The last release that is available from Marmalade is v2.4.1 but the current release is v2.7.0. Furthermore I believe the manuals are missing from the v2.4.1 tarball available from Marmalade, because Marmalade decided that the original tarball was to large and I had to remove the documentation to make it smaller. Otherwise I would not have been able to upload a new tarball at all.
That was the final straw and I decided to no longer attempt to upload new releases to Marmalade.
I suspect that many other packages also are no longer being updated on Marmalade. While it is still possible to upload new releases and (probably) new packages, that is only the case if you already have a Marmalade account. If you want to create a new account to be able to upload new packages, then you are out of luck - the maintainer does not respond to such (or any other) requests.
Marmalade is dying a slow death and you should move to Melpa or Melpa stable.

How can I speed this up?

Updating to v2.7.0 should help. Performance has improved since v2.4.1.
If that's not enough, then see the info node dedicated to performance issues.


text:
Cannot install Paredit
I am new to emacs.
I want to install paredit mode on emacs 24. I am using Melpa.
When i do M-x package-install RET paredit RET or try to install it from package-list-package i see the error in the minibuffer:
Cannot open load file: no such file or directory, paredit

What should i do to get it?

You should do M-x list-packages. Then do C-s to search for paredit. If it does not appear in the list, then your package source is not configured properly and you are not getting the list you are expecting. I just checked melpa on my local and paredit is present, so your invocation should have worked.


text:
Changing the completion speed in company
Is it possible to change the speed in which the company shows suggestions for completion? Per default it takes too long, so that it is still faster if one types the word himself than waiting for company suggestions.

It's a good idea to think of asking company-mode itself - see @DanJiadong's answer. The same technique applies generally. Start by C-h f ____mode or M-x customize-group etc. It is very easy to ask Emacs, once you get the habit of doing so.

Thanks for your comment. Does C-h f ____mode to all modes?

Not every mode name ends in "-mode", but most do. But C-h f applies to all functions, whatever the name.

M-x customize-group
Company
Company-idle-delay  (set this to a small value)


text:
Problem working with python/pygame
I encounter this problem almost always when i am working on a python-pygame project. Every second time when i evaluate the whole buffer with C-c C-c or with C-c C-l the pygame window open for a very short time and then every thing crashes including the python interpreter, and i get this error message:
Process Python segmentation fault (core dumped)

Does anyone know what the reason is and how can i fix it? I am on ubuntu 16.04 and using the default python-mode of emacs24.

This doesn't seem to be a problem with python-mode  but with your python instance.
This link goes into more detail, but it boils down to something has crashed. From the description you've given it sounds like your python instance is the crashing element. Double check that your python installed right. Considering that it is ubuntu, it should be fine. Next try reinstalling pygame. If your code is using a c compiled module make sure that it compiled right, and reinstall it.
Sorry that this is rather vague answer, if you provide code for evaluation I can go more in depth.


text:
Override c++-mode font lock
I am improving the C++ highlighting in Emacs with the minor mode: modern-cpp-font-lock.
Consider this following C++14 code:
int main() { int i = 1'2'3l; }

From cppreference.com

Optional single quotes(') may be inserted between the digits as a
  separator. They are ignored by the compiler.

In modern-cpp-font-lock, I set 1'2'3 to font-lock-constant-face and I set the integer suffix l to font-lock-keyword-face.
In fundamental-mode and modern-c++-font-lock-mode activated, I see the expected result. However, with c++-mode and modern-c++-font-lock-mode activated, '2' is highlighted as a string (l is correctly font locked).
I know the highlighting rely on the principle "first come first served" - meaning rules will not apply on words already highlighted.
Do you know if it is possible to override font-lock of a major mode? Or is it possible to change the order of rules to apply the font-lock (for example, longer rules first)?

Font-lock use two phases:

The syntactic phase. In this phase, Emacs determines things like strings and comments.
The keyword phase, i.e. the normal font-lock rules.

If you want to make Emacs ignore single quotes in digits, you have to do this in the first phase. Effectively, you will have to supply a custom syntax-propertize-function, which should set a suitable syntax-table text property on the quote character.
See this article on how to do this. Link broken, archived version.
Just remember that if you install your own syntax-propertize-function in a minor mode, you still have to ensure that the original function is executed.
Also, I've noticed that there is some work being done on modern C++ on the Emacs master branch, maybe this has already been handled there.

Yes there is some work done on the Emacs master branch. I send emails to the maintainer of cc-mode for bugs (single quotes in integers for example). However the release cycle on Emacs is too long (the fix in cc-mode won't be included in Emacs 25). That's why I provide this extended font-lock.

Please include answer instead of links... which are now broken.

@ideasman42, I agree that a full answer would be better. However, it would require quite some time to write such an answer -- time I currently don't have. Anyway, someone seems to have fixed the link, so I just leave it as it is for now.


text:
Paredit doesn't close {
I am using paredit. It terminates ( and [ and " fine, but does not close the { in any modes. How can i configure it to do this too? I have emacs24.

The commands are defined, but not bound to a key by default. You can add them to the paredit map with this:
(eval-after-load 'paredit
  '(progn
     (define-key paredit-mode-map (kbd "{")
       'paredit-open-curly)
     (define-key paredit-mode-map (kbd "}")
       'paredit-close-curly)))

You may prefer to add them to particular programming mode keymaps, rather than the paredit-mode-map; just modify accordingly.


text:
How to debug lack of response to a certain set of keystrokes?
Suppose I do a certain keystroke sequence in emacs, and nothing happens, even though I expect there to be a keybinding that would do something. This could be because:

The keybinding is not actually present.
The keybinding is invoking the command, but for some reason the command isn't having the expected effect.

How can I tell which of these it is? (The specific example is that I'm doing meta-q, which is supposed to be bound to the command fill-paragraph, but nothing seems to happen.)

Possible duplicate of M-< and M-> don't appear to work

You can determine which command a keybinding calls with C-h k then the keybinding.
In your example, you would enter C-h k M-q, which will tell you that M-q runs fill-paragraph (or at least it does by default in most modes).  If there's no command associated with the keybinding, Emacs will tell you so in the echo area.

You can try using (view-lossage) (bound to C-h l by default) to see if your terminal even recognizes keystrokes. Some terminals might have problems with certain keystrokes. This shouldn't be an issue if you're using a graphical display for emacs, but your window manager might grab some key combinations, and Emacs won't even know about them.


text:
Set specific TERM variable for only emacs terminals
I'm using multi-term right now in GUI cocoa emacs on OSX, and it works great in general. However, I'm running into a bit of an issue with my TERM variable. I generally set it to xterm-256color for iterm, but that causes odd behavior with terminal apps like htop in emacs multi-term. However, htop and other terminal apps work perfectly in multi-term when TERM is set to eterm-color.
As a result, I'm wondering if there is any way for me to have xterm-256color as the default coded in my .bash_profile, but have emacs automatically run TERM=eterm-color or a similar command when starting a new multi-term?

Terminals run inside of emacs set an environment variable, INSIDE_EMACS, so you can test that inside of your .bash_profile or .bashrc to set the TERM to something else.
(BTW on my system, multi-term seems to be setting TERM to eterm-color automatically…)

hmm, interesting. I did read that multi-term automatically sets TERM to eterm-color but it isn't working for me. I'll use the INSIDE_EMACS variable instead, thanks!

Expanding on @amitp's answer above, here's what I did in my .zshenv file to set my $EDITOR env variable:
if [[ -v INSIDE_EMACS ]]; then
    export EDITOR="emacsclient"
else
    # Regular shell
    export EDITOR="emacsclient -t"
fi


text:
Activate company in not all modes
Is it possible to define in which modes (programming languages) i want to have company activated? I want to have company in all my modes but not in lisp mode.

You can use company-global-modes to control that.

(setq company-global-modes '(not lisp-mode))
(global-company-mode 1)


text:
Binding compile command to a key for c++ code
Is it possible to bind the compile and run commands for a c++ code to a single key (for example F5). What i do at the moment is to run M-x compile and then as compile command g++ project.cpp and then i run ./a.out in a shell. Does anyone has a solution for doing these with less typing for c++?

You need to do two things: 1. Bind compile to a key (like f5) 2. Change the command that compile runs.
To do the first add (define-key c++-mode-map [f5] #'compile) to your .emacs.  This sets the key only in c++-mode; you can make it a global binding if you want by using global-map instead.
For the second, the compile function just runs whatever is stored in the variable compile-command.  Changing this globally would be a pain as you probably want different commands for different projects.  File local variables to the rescue.  Open the file and run M-x add-file-local-variable.  Chose compile-command as the variable and "g++ project.cpp && ./a.out" as the value (don't forget the quotes).  This will add a block
// Local Variables:
// compile-command: "g++ test.cpp && ./a.out"
// End:

to the bottom of your file.  You can easily add this block yourself if you like.
If your project has multiple files, use add-dir-local-variable instead.  Directory local variables are used by all files in that directory.

After adding the line to my init.el and reopening emacs i get this error: Symbol's value as variable is void: c++-mode-map.

That just means c++-mode isn't loaded yet.  Try wrapping it with  with-eval-after-load:  (with-eval-after-load "cc-mode" (define-key c++-mode-map [f5] #'compile)).  That way it won't run until after cc-mode loads and c++-mode-map exists.

Trying to do this and I cannot add a file local variable. Following your instructions, I get the error message: read-file-local-variable-value: Trailing garbage following expression. I am definitely using add-file-local-variable(not read). Even just pasting in the compile-command at the end of the file doesn't work. I still get prompted to enter a compile-command every time (with the usual make -k as default).

@n1k31t4 I don't recognize that error, but it still works on my machine.  Try asking adding more details and asking as a new question.

@erikstokes - it was  my mistake - using the function interactively, I did not place it within quotes.

I wonder why you use Emacs, if you don't write Elisp at all. For example, http://www.nathan1hughes.co.uk/programming/why-i-persisted-to-learn-emacs/ suits your question well, on the bottom of the blog:
 ;; Run C programs directly from within emacs
(defun execute-c-program ()
  (interactive)
  (defvar foo)
  (setq foo (concat "gcc " (buffer-name) " && ./a.out" ))
  (shell-command foo))

Not sure what the patronizing is for.


text:
Wrap/trunc text at 80 column width
Is it possible to wrap text automatically at 80 column length? I mean, writing code or text and then, when I reach 80 characters, put a breakline and continue on the next line (not wrapping the word but putting on the next line).
Thank you!

You can customize fill-column or do (setq-default fill-column 80) in your init file and use auto-fill-mode.
You can activate it per mode by using (add-hook 'text-mode-hook 'turn-on-auto-fill) or with key binding: (global-set-key (kbd "C-c q") 'auto-fill-mode). See emacswiki for more.

I did it, but it doesn't work :(

Did you also try auto-fill-mode?

Yes, and it only add spaces when the 80 characters are reached...

OP: Try starting from emacs -Q (no init file). If you still see a problem then provide a step-by-step recipe to reproduce it, saying what you see at each step and what you expected to see. If you do not see a problem, with emacs -Q, then recursively bisect your init file to find where you are introducing the problem.

I know you asked for "automatically" (and 5 years ago...) but...
I do it manually with the command fill-paragraph (M-Q). Having (setq fill-column 80) in the init file. It even understands some text structure, e.g. that the text is a comment. Which could be good or bad, depending on your needs.


text:
Kill like vim or Sublime Text
I'm "new" with Emacs. I'm making my own set up but I can't do one thing with killing words. You know what M-DEL does by default, but I want to make like Sublime Text or VIM. I'll do an example (this is the original text):
Hi, I'm captainepoch
< first post here!
And this is how I do on vim or Sublime Text:
Hi, I'm captainepoch
< first post here▮

Do M-DEL
Hi, I'm captainepoch
< first post▮

Do M-DEL
Hi, I'm captainepoch
< first▮

Do M-DEL
Hi, I'm captainepoch
<▮

Do M-DEL
Hi, I'm captainepoch
▮

Here, there's nothing at the beginning of the line and doing M-DEL in vim makes the cursor go to the end of the previous line.
Hi, I'm captainepoch▮

Do M-DEL
Hi, I'm▮

Do M-DEL
Hi, I'▮

Do M-DEL
Hi, I▮

Do M-DEL
Hi,▮

Do M-DEL
Hi▮

This final M-DEL will end up deleting the whole text.
▮

A friend of mine did this function:
(defun backward-kill-word (arg)
  (interactive "p")
  (let ((init-pos (point))
        (line-begin (line-beginning-position)))
    (if (/= (point) line-begin)
        (kill-word (- arg)))))

And it does the job until it got the <, which does this:
Hi, I'm captainepoch
<▮

Do M-DEL
Hi, I'm▮

Welcome to Emacs.SE!  Could you please clarify exactly what you want your function to do?  It's a little hard to follow what you want from the example.

Hi @Dan, thank you! I want to delete words individually, in the example it does from bottom to top. When I use emacs and do M-DEL, It deletes words but if the last 2 characters are <  (< and a space), it deletes that two and the previous word on the previous line. I'd like to delete text as Sublime does.

@captainepoch I have updated the question.. I hope that's what you meant.

@captainepoch syntax-subword package might get you close to what you want; I have not used it.

@KaushalModi Thank you so much, It's just what I mean! And the package works like a charm!

I came from sublime as well and was looking for the behavior. I achieve the results you are describing by using syntax-subword which I think can be installed through MELPA. Here is my syntax-subword configuration (I use use-package):
(use-package syntax-subword
  :init
  (setq syntax-subword-skip-spaces t)
  :config
  (global-syntax-subword-mode))

For you, it should be enough to do M-x package-install syntax-subword, and then add the following to your config file:
(setq syntax-subword-skip-spaces t)
(global-syntax-subword-mode))

I hope this setup works for you; it has been so long since I have configured Emacs without use-package that I might have missed a step (e.g., you may need to require the package). However, on my setup using that package I tested your example, and it works the way you want it to.

You solution is just what I want, thank you so much!


text:
Delete 4-spaces as a single tab
I asked another question yesterday but this bothers me a little. I use 4 spaces as indentation for programming (ShellScript, C and Python, mostly). When I want to delete the 4 spaces, I had to do one by one. When I was using vim, I didn't have to do in that way.
What I want to set up is that, when you put the cursor at the beginning of the first word after indentation and press DEL, it deletes the 4 spaces at once.
An example:
int main () {
    ▮int a = 0;
    if (a = 0) {
        printf("Hello!");
    }
    return 0;
}

int main () {
▮int a = 0;
    if (a = 0) {
        printf("Hello!");
    }
    return 0;
}

(Suppose that ▮ is with the i).
Is it possible to do that in emacs?

Result of doing C-u C-x = on the indentation:

I have tested in emacs -Q that C-u <backspace> will delete 4 spaces backwards.
Equivalent bindings would be:

M-4 <backspace>
C-4 <backspace>

Before
int main () {
    ▮int a = 0;

(▮ represents point)
Do C-u <backspace> or C-u DEL.
After
int main () {
▮int a = 0;

By default C-u represents a repetition or 4 for most commands (usually navigation related).

Update
To delete 4 space to the right of the cursor, do C-u C-d instead.
Before
int main () {
▮    int a = 0;

(▮ represents point)
Do C-u C-d.
After
int main () {
▮int a = 0;

On emacs 25.1.50.x (emacs master branch as of now), <backspace> or DEL is bound to the backward-delete-char-untabify command by default.

I understand what you tell me, but I don't convert the spaces to TABs or viceversa in real time, I have changed it in the config for every indentation.

Hmm, then I do not understand your question.. the question says "Kill 4-spaces .."

From the cursor to the point of where the 4 spaces start. It's like treating 4-spaces as a unique tab, not converting it in real time to delete it.

@captainepoch It's not clear if you are trying to delete 4 ASCII Space characters (0x20) or an ASCII TAB character (0x09). What do you see when you do C-u C-x = with cursor on the area that you call "4 spaces".

I see this (I hope it's what you asked for, large image, that's why I didn't use MD's image syntax) https://i.imgur.com/3I4a2Ep.png

@captainepoch OK, I added the same code in c-mode in an emacs -Q session and I still cannot recreate your scenario. From the C-u C-x = result (very helpful!), I see that there's a before-string overlay active where the cursor is. I do not use c-mode and so I am not very familiar with it. Do you have any other minor mode or c-mode setting enabled that would put those overlays?

No, I don't. I tried on an HTML file on web-mode, but nothing about before-string appeared... At c-mode I got this settings: https://github.com/captainepoch/dotfiles/blob/master/.emacs.d/config/c_dev.el

@captainepoch Actually, nevermind, those overlays are related to linum-mode. So those characters do look like physical spaces (tabs) because the ASCII code is 0x20. If you can C-f/C-b 4 times in that indentation, that's another proof that those are physical space characters. Then the above solution should work for you. In your screenshot, did you select all the spaces and then do C-u C-x =? Why does the whole indentation before return look selected?

I selected it, yeah. This is a screenshot without selecting the indentation (http://i.imgur.com/AQl7uic.png). What I want is deleting the 4 spaces as a tab with the DEL key.

@captainepoch That's a perfect screenshot! So basically those are just spaces; forget that you hit TAB to make that indentation. So one DEL will delete just one space. To delete all 4 spaces to the left of the cursor, do C-u DEL as I mentioned above in the answer. If you want to delete 4 spaces to the right of the cursor, do C-u C-d.

@captainepoch I have updated the answer; hope it is clearer.

It does, I'll try to make a function to do the work pressing DEL. Much appreciated, Kaushal Modi :)

C-u <backspace> deletes EXACTLY 4 characters. It does not respect tab stops. It does not respect indentation settings. It will do the wrong thing if there are tab (or other) characters instead of spaces. It just so happens that one C-u means "repeat four times" which is a common indentation width. This answer addresses the letter of the question, but I think an answer that would be more in the spirit of the question (delete whitespace characters until the previous tab stop) would be more useful.


text:
Enable hl-line-mode globally
Running M-x hl-line-mode enables highlighting for the current buffer.
How can i set highlighting current line to be enabled in init.el?

just add this to your .emacs or init.el file : (global-hl-line-mode 1).

so easy was that! :-)

If you want to customize any part of emacs, press M-x RET customize-group RET emacs RET. A buffer will open listing all the groups you can customize in emacs(like editing, programming, environment, etc.). There will also be a search field in the top of the buffer. You could also enabled hl-line globally by going to customize-group, and setting the global-hl-line-mode to a non-nil value.

@Chakravarthy Raghunandan answered your question completely and succinctly.
But you owe it to yourself to learn to ask Emacs -- that will help you much more, both immediately and in the long run.  One of the goals of this particular Stack-Exchange site is to help not only by answering specific questions, but by helping you learn to help yourself.
This kind of question is answered immediately by asking the Emacs manual (C-h r) what it has about hl-line-mode: just type i hl-line-mode (i is bound to the command Info-index).  That takes you immediately to node Cursor Display of the manual, where you see this:

To make the cursor even more visible, you can use HL Line mode, a minor mode that highlights the line containing point.  Use M-x hl-line-mode to enable or disable it in the current buffer.  M-x global-hl-line-mode enables or disables the same mode globally.

It really couldn't be simpler, in this case.  No need to open a web browser, go to a Q&A site, and type up your question.  Just ask Emacs.
You have the hypertext manual(s) ready-to-hand at all times when you are in Emacs. C-h i opens the manuals browser (Info) for any installed manual, including the Emacs manual and the Elisp (Emacs-Lisp) manual. If you haven't yet taken time to get to know Info, I recommend you start by looking at the Info manual about Info: C-h i m Info.

What do I have to do when C-h r i gives me The Info diretory node has no index_?

Which manual has no index? I'd suggest filing a bug to the maintainers of the relevant library, if not part of regular Emacs, or M-x report-emacs-bug if it is part of regular Emacs. i is generally recommended as the best (or one of the best) ways to find stuff in Emacs. If some manual has no index then I'd consider that a bug, or at least a place where there's room for improvement.

But you said C-h r, which is the Emacs manual. It definitely does have an index. Perhaps you are doing something wrong. Do you see the same problem (no index) if you start Emacs using emacs -Q (no init file)? If not then bisect your init file to find the culprit.

And I see now the error message you quote says that you are not in any manual - you are at the directory node, which is above all manuals. So see previous comment - clearly C-h r didn't take you to the Emacs manual, or you didn't actually use C-h r.

See @Drew It is not so easy as you stated. Of course I hit C-h r.

If C-h r doesn't take you to the Emacs manual then the problem is likely in your init file. Do you see the same problem when you start using emacs -Q?

Someone want to explain the downvote?

Someone want to explain another downvote?

If C-h r isn't taking you to the manual, then you have a broken (incomplete) installation of Emacs.  The scenario I'm aware of in which this commonly happens is on Debian-based systems (such as Ubuntu), which is explained at https://emacs.stackexchange.com/questions/48211/emacs-manuals-are-missing-on-debian-ubuntu

(global-hl-line-mode t) ;; put this in your .emacs.d/init.el or .emacs file
if you want to trigger this only when you are in gui emacs then put this instead
(when window-system (global-hl-line-mode t))
you can toggle this minor mode using the command
M-x global-hl-line-mode
when you just want it temporarily
if you only want to trigger this in your current buffer use
M-x hl-line-mode
Note this is a toggle so that M-x hl-line-mode (a second time) will disable it.


text:
Emacs doesn't display color fonts at all

I tried to add Noto Color Emoji from Google Noto as my font for Emoji in GNU Emacs, as mentioned in here, but for some reason GNU Emacs doesn't display these characters properly in its window. I'm using GNU Emacs 24.5.1 on GNU/Linux. Is this a bug or am I doing something wrong?

You're not doing anything wrong.
Emacs for Linux uses XFT for font rendering, and XFT doesn't yet support the color fonts. See this mailing list thread from Dec 2015. Richard Stallman writes in that thread that it's a low priority and they don't care about color fonts. Also in that thread you can see that they disabled color fonts in Emacs for Mac, not for any technical reason but because color fonts are not supported in the Unix version of Emacs and they don't want the Mac version to have a feature that is not in the Unix version.
So I wouldn't expect to see this any time soon.

Actually, the feature is available in some development builds: ...* Changes in Emacs 27.1 ... ** Multicolor fonts such as "Noto Color Emoji" can be displayed on Emacs configured with Cairo drawing and linked with cairo >= 1.16.0. ...

That's great to hear!

Or you can use Emacs terminal (emacs -nw) on a terminal emulator that support color emoji.
Edit:
Emacs can be run as GUI or terminal application. To start emacs terminal, open your terminal emulator (iTerm or iTerm2 in MacOS, Mate-Terminal or Gnaome-Terminal in Linux) and run the command emacs -nw in the terminal emulator. When running in terminal mode, the glyphs and fonts are not in control of Emacs and it must display what the terminal emulator is giving. With a terminal that support color emojis, you can force Emacs terminal to display them.

Can you elaborate on your answer?

Color emojis work with the noto color emoji and other emoji fonts  in emacs 28
I tried to use emojis in the terminal on emacs 26 but it was glitched when I scrolled up and down. That was fixed when I upgrade as well
Now I am using GNU Emacs 28.0.50

Please specify the Emacs release or prerelease info for the build you're using. Just "2020" doesn't mean much.

MS-Windows? macOS? or GNU/Linux? Please clarify


text:
Custom C-arrow cursor movement
I was not satisfied with the behavior of standard C-arrow and C-S-arrow, so I wrote this functions to replace standard ones.
(setq separators-regexp "[\-'\"();:,.\\/?!@#%&*+=]")

(defun forward-to-separator()
    "Move to the next separator like in the every NORMAL editor"
    (interactive)
    (let ((my-pos (re-search-forward separators-regexp)))
        (goto-char my-pos)))

(defun backward-to-separator()
    "Move to the previous separator like in the every NORMAL editor"
    (interactive)
    (let ((my-pos (re-search-backward separators-regexp)))
        (goto-char my-pos)))

(global-set-key (kbd "C-<right>") 'forward-to-separator)
(global-set-key (kbd "C-<left>") 'backward-to-separator)

But now I am facing a problem with shift selection: it actually just not working at all.
So my question is: how can I select text using my new functions and shift key(C-S-arrow)?
My final code is here:  https://gist.github.com/FirstTimeInForever/8303ac1918c81365991d7acf7a926bd8
I added C-<backspace> support and changed my regex. Now I can move cursor like in sublime text!

Why not just set a mark (C-<SPC>) from where you want to select and proceed to use your cursor movement functions?

I know I can set a mark, but selecting text with shift is more comfortable for me.

Excelent, do you know how to implement jumps over black characters ?

Use (interactive "^") instead of (interactive).
C-h f interactive tells you, way down near the bottom:

If the string begins with ^ and shift-select-mode is non-nil,
   Emacs first calls the function handle-shift-selection.

In your case, the commands do not take an argument.  But you can still use a string argument to interactive, in this case "^", to make the command respect shift selection.

I upgraded your code so cursor navigation is now behaving a lot better then default setting in Atom editor. Mainly I added skipping blank spaces in file.
I highly recommend binding those to C-<right> and C-<left> because in CUA mode, C-S-<right> and C-S-<left> is automatically binded to skipped text selection so you can easily copy/remove as in other editors.
(require 'cl-macs)

(setq custom/separators-regexp
      "\\([]['\"(){};:,.\\/?!@#%&*+=^[:space:]\n-]\\|\\s_\\|\\`\\|\\'\\)")

(defun custom/position-normalize-forward (saved-pos my-pos)
  (if (>= (- my-pos saved-pos) 2)
      (progn
        (goto-char my-pos)
        (if (not (eq my-pos (point-max)))
            (progn
              (custom/backward-symbol))))
    (progn
      (goto-char my-pos))))

(defun custom/forward-symbol ()
  (interactive "^")
  (block custom/forward-symbol
    (let* ((saved-pos (point))
           (my-pos (re-search-forward custom/separators-regexp))
           (my-pos2 (custom/find-blank-space t saved-pos)))
      (if (> my-pos2 my-pos)
          (progn
            (goto-char (- my-pos2 1))
            (return-from custom/forward-symbol)))
      (if (eq my-pos 1)
          (progn
            (goto-char (+ my-pos 1))
            (setf my-pos (re-search-forward custom/separators-regexp))
            (custom/position-normalize-forward saved-pos my-pos))
        (custom/position-normalize-forward saved-pos my-pos)))))

(defun custom/position-normalize-backward (saved-pos my-pos)
  (if (>= (- saved-pos my-pos) 2)
      (progn
        (goto-char my-pos)
        (if (not (eq my-pos 1))
            (progn
              (custom/forward-symbol))))
    (progn
      (goto-char my-pos))))

(defun custom/backward-symbol ()
  (interactive "^")
  (block custom/backward-symbol
    (let* ((saved-pos (point))
           (my-pos (re-search-backward custom/separators-regexp))
           (my-pos2 (custom/find-blank-space nil saved-pos)))
      (if (< my-pos2 my-pos)
          (progn
            (goto-char (+ my-pos2 1))
            (return-from custom/backward-symbol)))
      (if (eq my-pos (point-max))
          (progn
            (goto-char (- my-pos 1))
            (setf my-pos (re-search-backward custom/separators-regexp))
            (custom/position-normalize-backward saved-pos my-pos))
        (custom/position-normalize-backward saved-pos my-pos)))))

(defun custom/find-blank-space (go-forward starting-pos)
  (let ((starting-char (string (char-after starting-pos)))
        (skipped-count 0)
        (increment (if go-forward 1 -1))
        (should-loop t))
    (if (or (equal starting-char " ")
            (equal starting-char "\t")
            (equal starting-char "\n"))
        (progn
          (while should-loop
            (if (or (equal (string (char-after (+ saved-pos skipped-count))) " ")
                    (equal (string (char-after (+ saved-pos skipped-count))) "\t")
                    (equal (string (char-after (+ saved-pos skipped-count))) "\n"))
                (setq skipped-count (+ skipped-count increment))
              (setq should-loop nil)))
          (+ starting-pos skipped-count))
      starting-pos)))

Hope it will help.


text:
Running kivy code in Emacs
I am learning about the kivy library for python. I have a test code which i run with C-u C-c C-c after having the python interpreter fired up with C-p. It runs fine the first time and the window opens, but trying to run it a second time makes nothing happen; the window doesn't show, only in the minibuffer below i see Sent: import kivy.
import kivy
kivy.require(kivy.__version__)
from kivy.app import App
from kivy.uix.label import Label

class MyApp(App):
        def build(self):
                return Label(text = "Guido Van Rossum", font_size = 90)

def main():
        MyApp().run()

if __name__ == "__main__":
        main()

Does anyone have experience with writing kivy using emacs, or can any one help?
Edit
This is what i get in the terminal the second time i run the code:
>>> [INFO              ] [Base        ] Start application main loop
[ERROR             ] [Base        ] No event listeners have been created
[ERROR             ] [Base        ] Application will leave

Does it work if you simply type main() or if you remove if __name__="__main__"?

(Edited - nothing happening is hardly the same as a "crash".)

@Jules No, no changes.

This is not specific to kivy, but, in general, if you want to figure out what's going on inside your application, there are tools to do just that. For instance, there's a debugger, which is also possible to call from Emacs: http://stackoverflow.com/a/2325751/5691066

I think this issue is caused by the fact that if you run the script with C-u C-c C-c and then run it a second time the same way, you are trying to run it as part of the same process/session (not sure the correct term). To illustrate this, if it needs illustrating, you can visit the *Python* buffer that will be open after you run the script, and at the interactive prompt and call the dir() function. You will see that 'App', 'Label', 'MyApp', 'kivy', etc. are already there.
For reasons that I can't really explain, but that have also been mentioned here, kivy will not work this way if you try to run the same App twice in the same session while everything is still in memory.
If you run your .py file from the command line with python myfile.py it will work every time you run it because you are starting from scratch each time. But if you open ipython or another interactive interpreter, import your module, and then call the main() function more than once, you will see the same errors for the same reason.
You will see that if you got to the *Python* buffer and type exit() to end the Python process, and run your script again with C-u C-c C-c, that it should work as expected again (although only once, of course, for the reasons described above). This is not an issue with Emacs really, but a product of the way that kivy works and the way the running Python scripts works in Emacs. I don't think it is something that you will easily be able to "fix", nor should you really need to. However, this will hopefully put your mind at ease if you were worried that it was a bug or something.
Emacs and kivy do play well together in my experience (I used them together every day at my last job), so I hope this little quirk doesn't bother you too much!

However in my experience i have always had some kind of problems with Emacs + Python, also i number of problems when writing Pygame, it mostly costs me to understand the problems why the code crashes in emacs and to fix it and get it to work properly than writing the program itself! For Python there are some other editors out there which really help one for writing python than get your head exploded because of some other stuff not related to the program.

@amirteymuri I understand what you are saying, but in my experience, this is true for all editors. No editor is perfect, and if you are particular about how your editor works (which I am) you will experience some frustration when it doesn't work the way you want. The reason I use Emacs is that when something breaks or doesn't work the way I want, 99 out of 100 times I can a). fix it myself, b). get the answer from this great community. I personally can't do this with other editors. I guess what it comes down to is: use the tool that works for you. For me that is Emacs.

I use Emacs for writing c or clojure, but for python my experience have been till now DISASTER! May be you could give me some of your experience, how do you test or run parts or whole of your programs in emacs? Do you run them in an external terminal?

@amirteymuri yeah, I almost always use an external terminal for testing and running code. I also, use anaconda-mode which I really like, and have used elpy in the past. Both of these packages make things a lot easier. I find anaconda-mode to be much simpler, and requires less tweaking for me. I don't really feel like Emacs is any more suited for writing Python than any other editor; it is really the non-Python packages and features that make me love Emacs, and I like having everything in one editor so I stick with it even when an editor built just for Python might do some things better.

I have the same problem, using kivy in Spyder editor. As mentioned in previous answers it happens for the way kivy works. But I found a work around for it here and here Which I copy paste below.
Define the reset() function below, and simply run it BEFORE running your instance_of_App().run() method.
def reset():
import kivy.core.window as window
from kivy.base import EventLoop
if not EventLoop.event_listeners:
    from kivy.cache import Cache
    window.Window = window.core_select_lib('window', window.window_impl, True)
    Cache.print_usage()
    for cat in Cache._categories:
        Cache._objects[cat] = {}


text:
How to increase height of minibuffer/mini-window in Spacemacs?
Steps to take to appreciate my befuddlement:

Run Spacemacs.
Press the space bar.
This moves the mode line up, and in the area below the mode line (which I think is all called either the mini-window or the minibuffer), displays keys that the user might wish to press next in order to execute a command, e.g. SPC → avy word, TAB → last buffer, etc. Unfortunately, only 9 lines of these are shown (when Spacemacs is maximised; 10 lines if I go fullscreen), so some of the options are hidden on a second page. Below this, there is a line that reads, SPC- Spacemacs root (1 of 2) [C-h paging/help].
Press Ctrl+h.
That last line now reads, SPC- n → next page, p → previous page, u → undo-key, h → help, a → abort.
Press n.
Aha! Now we can see the second page's worth of options.

I'd like to make it unnecessary to have to press SPC C-h n to see those remaining options. I figure this can be done by increasing the height of the area under the mode line, so that all the options can fit on one page.
My questions:

How can I do this? I've already tried increasing max-mini-window-height from 0.25 to 0.5 and reloading Spacemacs, but this didn't appear to make any difference at all.
What is the correct terminology for the area that appears below the mode line when pressing the space bar in Spacemacs?

This feature is provided by which-key.
The popup is actually a side window, not the minibuffer itself, so it is not affected by max-mini-window-height.
If your popup is at the top or bottom, increase which-key-side-window-max-height as necessary to eliminate the pagination. If your popup is at the left or the right, adjust which-key-side-window-max-width instead.

How can I do it also for the minibuffers open for helm?


text:
Run a command with C-c C-c for a specific major mode
I have a file with a .md extension, and I want to run a command to interpret/parse a file when markdown-mode is active with a C-c C-c key combination, for example. I want to run this shell command:
aglio -i foo.md -o foo.html

Wherefoo.md is the file name of the current buffer and foo.html is this name with replaced extension (to html). How can I do this in Emacs?

C-c C-c make different things into different major modes, in org-mode it have very much location-specific commands.  But you could bind this on any key you want.  But into markdown-mode the C-c C-c is the prefix key, so you'd better don't rebind it.

Running shell command could be done with (shell-command COMMAND).  Then we need to make string for executing command.  We'll concatenate it from sections with (concat ...).  We have 5 sections of the command:
(concat "aglio -i "                                    ;; 1
        (buffer-file-name)                             ;; 2
        " -o "                                         ;; 3
        (file-name-sans-extension (buffer-file-name))  ;; 4
        ".html")                                       ;; 5

So, if the buffer file name is foo.md, then result of this script will be
aglio -i foo.md -o foo.html

We could make it function, like next:
(defun aglio-current-file ()
  "Execute aglio shell command on current file"
  (interactive)
  (shell-command
    (concat "aglio -i " (buffer-file-name)
     " -o " (file-name-sans-extension (buffer-file-name)) ".html")))

We could define key for markdown-mode-map with next code
(eval-after-load 'markdown-mode
  '(define-key markdown-mode-map (kbd "C-c C-c s")
    'aglio-current-file))

I use C-c C-c s instead of C-c C-c cause this version of the markdown package from melpa uses C-c C-c as prefix for buffer-wide commands.


text:
Can't change the line-highlight color
I try to set a new hex-color to highlight the current line in the distinguished theme, but this can have no effects. I put this in init.el:
;;highlight current LINE
(global-hl-line-mode 1)
(set-face-background 'hl-line "#47310D")
(set-face-foreground 'highlight nil)

How can i change the color of the current line?

Are you place this after loading theme?

Sometimes getting these customizations applied at the correct time is tricky. Maybe it will be easier to use M-x customize-group hl-line than to do this in your init.el?

@KonstantinMorenko No its placed before (load-theme 'distinguished t)

So, load-theme could change value of this variable.  Try to place setting face after load-theme.

@KonstantinMorenko Perfect, this works!

When you put your code before load-theme, loading theme could change value of this variable.  Put your code after load-theme in your init.el.


text:
Changing the Variable Pitch Font
Is there a way to change the font associated with the variable-pitch-mode? On my emacs installation enabling variable-pitch-mode changes the font to a sans-serif font; I would like to use a serif font instead.

It seems that function variable-pitch-mode hard-codes the use of face variable-pitch.  I think your two choices (other than perhaps advising that function) are these:

Use face variable-pitch.  Just customize it to be have any appearance you want: M-x customize-face variable-pitch.
Write your own command, similar to variable-pitch-mode.  That definition is very short.  You need only substitute your own face for face variable-pitch in that definition.  (You could also define your command using buffer-face-mode-invoke, which is what variable-pitch-mode uses.)
For example:

    (defun my-variable-pitch-mode (&optional arg face)
      "MY Variable-pitch default-face mode.
    An interface to `buffer-face-mode' which uses FACE
    \(`variable-pitch', by default).
    Besides the choice of FACE, it is the same as `buffer-face-mode'."
      (interactive (list (or current-prefix-arg 'toggle)))
      (buffer-face-mode-invoke face arg (called-interactively-p 'interactive)))

In fact, I'll (or you can) suggest that as the definition of variable-pitch-mode, using M-x report-emacs-bug.  (I've done that now - bug #24594.)

Wonderful. I didn't know how variable-pitch-mode worked; thank you for explaining it to me. I personally am fine with customizing the variable-pitch face, but I agree that it makes sense to have the option to change the face associated with variable-pitch-mode, so I hope that functionality gets added eventually.

Doesn't look like it will. But if customizing the face is all you need here, then that's good.


text:
Strange Errors in Python-Mode
I am using the python mode. When i try to evaluate the following def using C-M-x i get this error from the python interpreter which looks strange:
def foo(*args, **kwargs):
    print args, kwargs

>>> Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/amir/programming/python/tst.py", line 2
    if True:
           ^
IndentationError: expected an indented block

Can any one say why this happens? The file is only including the above function definition beginning from the first line an nothing more.

Looks like code was sent to a Python3 shell, where print is a function.
M-x py-execute-def-python2 RET should work.
Customizing py-shell-name is an option too.


text:
Evil mode and regular expressions
In Vim, if I want search for all variable names LX where X is a number, I can simply type /L\d. However, this doesn't seem to work with evil.
Is there another syntax for regular expressions in Evil mode, or will I have to fall back on some Emacs functionality for search and replace using regular expressions?
I am using spacemacs, and I am pretty clueless regarding most things in Emacs, happily staying in Evil mode all day :).

Where are you trying to search? In a document or in emac's global variables?

I am searching in a text document

Are you using isearch or something like helm-swoop or swiper? The last two should be able to do what you want easily. If you want to use the normal isearch function but want to use a different regexp engine look at https://github.com/benma/visual-regexp-steroids.el

evil uses the Emacs regexp facilities under the hood.  Unfortunately, Emacs does not appear to have a separate syntax
class for digits, and does not recognize the \d regexp class.
So, to match your variable named LX where X is a digit, it
looks like you're stuck with the clunky /L[0-9] or the even clunkier /L[[:digit:]].
Note that, in principle, it looks like you could use character
codes
as listed by describe-categories:
`\cc`

matches any character whose category is *c*.  Here *c* is a
character that represents a category: thus, 'c' for Chinese
characters or 'g' for Greek characters in the standard
category table. You can see the list of all the currently
defined categories with `M-x describe-categories RET`. You can
also define your own categories in addition to the standard
ones using the `define-category` function (see Categories).

According to describe-categories, digits are category 6.
Hence, /L\c6 should work (although it doesn't for me, even
though other categories do).  Still, you wouldn't be saving
yourself much awkward typing when compared to /L[0-9].

Thank you very much! Think I can live with the clunky syntax for now. Just happy to search replace in a more conveniently way again, and I just tested that it even works with capture patterns, yay!


text:
Customize theme font color
I am using the distinguished theme. I want to set the main font color to something more dark, how could i do that?

You can use describe-face to get the name of the face at point.
And you can change the color with custom-set-faces.
(custom-set-faces
  '(default ((t (:foreground "khaki4" :slant italic)))))