How to check which Emacs I am using? - emacs

I have two Emacs (Aquamacs and text-based Emacs) on my Mac.
In my .emacs file, I can check if I'm using Aquamacs with ...
(boundp 'aquamacs-version)
How can I check if I'm using text based emacs?
EDIT
Jürgen Hötzel's answer works, but for text based emacs, using
(unless (null window-system) ...)
is better as (window-system) is not defined.

M-x emacs-version
ad some more characters here......
Sorry, from .emacs, just call
(emacs-version)

I know this question was answered a long time ago, but I found another answer by typing emacs --help. This gives a list of options in which you can find emacs --version.
In my case, emacs --version prints: GNU Emacs 24.3.1.
I have only tested this solution on Linux with my current version of Emacs. I do not know if the same solution applies to Windows, or to older versions of Emacs, but in theory it should.

(if (window-system)
"window-based"
"text-based")

Or, you could use this:
(if (or (eq window-system 'ns)
(eq window-system 'mac))
(message "hello, world!"))
It will only print "hello, world!" when you run a graphical Emacs in OS X.

Errr... (not (boundp 'aquamacs-version)), perhaps?

Related

What is the Emacs keyboard shortcut for the Agda 𝕃 symbol?

I mean the list symbol in case it does not show up well in the title.
It is not \bl like the book says.
The book provides the code to make typing easier in the "Some Extra Emacs Definitions" addendum:
(eval-after-load "quail/latin-ltx"
'(mapc (lambda (pair)
(quail-defrule (car pair) (cadr pair) "TeX"))
'( ("\\bb" "𝔹") ("\\bl" "𝕃") ("\\bs" "𝕊") ("\\bt" "𝕋") ("\\bv" "𝕍") ("\\cv" "⋎") ("\\comp" "○") ("\\m" "↦") ("\\om" "ω"))))
You just need to copy it from here and paste it into your .emacs file.
It's not part of the emacs mode yet but I have submitted a Pull Request to add the missing blackboard bold letters.
Use M-x then agda-input-show-translations get a table of all the character bindings. Then you can use C-s to search for a specific character.
In my case I just typed in Emacs
\bL
, which gives me the blackboard bold font correctly. This is with agda 2.5.3 (installed via hackage per official documentation under Ubuntu 16.04)

Emacs Windows org-mode encoding

I have an org-mode file for todos, and I have renamed the todo bullets to "Att göra" (TODO in swedish). However org-mode (in Windows, see exact version below) think it is "Att göra" (pressing M-S-RET). I can see åäö correct, but "Att göra" is not intepreted as a TODO item. I can also see in the configuration files that it is spelled "Att göra", still org-mode think it is "Att göra".
I have tried to save the configuration files and my org-mode file in UTF-8 (C-x RET f utf-8 RET). I have the following in my Emacs configuration:
;; Prefer utf-8
(prefer-coding-system 'utf-8)
(setq coding-system-for-read 'utf-8)
(setq coding-system-for-write 'utf-8)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(inhibit-startup-screen t)
'(keyboard-coding-system (quote utf-8))
'(selection-coding-system (quote utf-8)))
This happens only in Emacs for Windows (I think this is the version number):
GNU Emacs 24.3.1 (i386-mingw-nt6.1.7601) of 2013-03-17 on MARVIN
It works in Mac, Cygwin (however I have trouble with M-S-RET as the terminal doesn't transfer that sequence right, despite that I have disabled the Alt-Enter shortcut to go fullscreen), Linux etc. It is only in Emacs Windows standalone client.
If you have any idea why this is, I would be very greateful for your suggestions.
I want to leave this question answered.
Brady told med to add
(modify-coding-system-alist 'file "" 'utf-8-unix)
to my Emacs file and it works! No idea what it really does.

Filename in chinese shows as unicode characters

when using C-x C-f, the filename which includes Chinese characters are shown as following:
How can I configure it to show Chinese words? Thank you.
=====updated=======
System: OS X 10.8.4
Emacs version: GNU Emacs 24.3.1 (x86_64-apple-darwin)
I think this may be caused by one of those annoying interactions between the operating system and Emacs. Emacs doesn't seem to know how to interpret the file names, so let's try to help it by inserting this in your .emacs file.
(setq default-buffer-file-coding-system 'utf-8-unix)
(setq default-file-name-coding-system 'gb2312)
(setq default-keyboard-coding-system 'utf-8-unix)
(setq default-process-coding-system '(utf-8-unix . utf-8-unix))
You may need to try a different system instead of gb2312.

What happened to the ido-imenu in ruby-mode function in Emacs24?

Emacs 23.2 in emacs-starter-kit v1 has C-x C-i (or ido-imenu) (similar to Sublime Text's Cmd+R). Emacs24 in emacs-starter-kit v2 lacks this function. I found this github issue and a fix, which try to recreate the functionality. While this ido-imenu works in elisp-mode, it stopped working in ruby-mode. I get:
imenu--make-index-alist: No items suitable for an index found in this buffer
Has anyone figured out how to get this to work?
Why was this taken out of Emacs24?
Is there a new replacement for this function?
Since the function is part of ESK (as opposed to something budled with Emacs) you'd probably do best to report the bug upstream. On a related note ESK main competitor Emacs Prelude offers the same functionality (bound to C-c i by default) and it seems to be working fine with ruby-mode in Emacs 24. Here you can find more on ido-imenu.
So I finally figured it out, after reading the Defining an Imenu Menu for a Mode section on emacs-wiki again.
Short answer: you need to add this bit to your customization. Feel free to add more types to the list (I am happy with just methods).
(add-hook 'ruby-mode-hook
(lambda ()
(set (make-local-variable imenu-generic-expression)
'(("Methods" "^\\( *\\(def\\) +.+\\)" 1)
))))
Longer answer: I first tried to define a ruby-imenu-generic-expression function and set that to imenu-generic-expression by using the ruby-mode-hook:
(defvar ruby-imenu-generic-expression
'(("Methods" "^\\( *\\(def\\) +.+\\)" 1))
"The imenu regex to parse an outline of the ruby file")
(defun ruby-set-imenu-generic-expression ()
(make-local-variable 'imenu-generic-expression)
(make-local-variable 'imenu-create-index-function)
(setq imenu-create-index-function 'imenu-default-create-index-function)
(setq imenu-generic-expression ruby-imenu-generic-expression))
(add-hook 'ruby-mode-hook 'ruby-set-imenu-generic-expression)
This however did not work (I would get the same error as before). More reading of the Defining an Imenu Menu for a Mode section showed me the way. Now, I'm not an elisp expert, so here's my hypothesis: basically, the above method works for modes where the
major mode supports a buffer local copy of the “real” variable, ‘imenu-generic-expression’. If your mode doesn’t do it, you will have to rely on a hook.
The example for foo-mode made it clear how to do it for ruby-mode. So it appears that ruby-mode does not have a buffer-local copy of the real imenu-generic-expression variable. I still can't explain why it worked in Emacs 23.2 (with ESK v1) but does not on Emacs24, but hey at least I found a working solution.

How to do use C-x k to kill an Emacs buffer opened in server mode?

I use windows batch file to open files in an already-running instance of Emacs using emacsclientw.exe. However, any file opened that way is opened in server mode, which means that I have to use C-x # to kill it, instead of the usual C-x k. How do I change this behavior?
My solution was to rebind it (well M-w actually) to:
(lambda ()
(interactive)
(if server-buffer-clients
(server-edit)
(kill-this-buffer)))
[edit: having now read the code for server-edit, it might be better to use server-done (depending on what you want). server-edit will switch you to a server-edited buffer (if any still exist) but server-done will simply switch you to the next buffer. You could also use the output of server-done to see if the buffer was actually killed (not the case if the file was open before invoking emacsclient) and then kill it if not. Or use server-kill-buffer as suggested elsewhere.]
Here is what i put in my .emacs to do this :
(add-hook 'server-switch-hook
(lambda ()
(local-set-key (kbd "C-x k") '(lambda ()
(interactive)
(if server-buffer-clients
(server-edit)
(ido-kill-buffer))))))
Like this C-x k work the usual way when i'm not finding a file from emacsclient (which for me is ido-kill-buffer), and if i'm using emacsclient, C-x k does server-edit if the client is waiting, or run ido-kill-buffer otherwise (if i used emacsclient -n).
use:
D:\> emacsclientw -n foo.txt
the -n says "no wait". This is in GNU Emacs 22.2.1 (i386-mingw-nt5.1.2600) of 2008-03-26 on RELEASE (and many prior versions, IIRC).
You know, I hate to suggest workarounds instead of a real solution... but after reading the server code, I am confused as to how emacs even determines that a buffer is a server buffer.
With that in mind, why not open up files like:
emacsclient --eval '(find-file "/path/to/file")'
This way emacs doesn't know that your buffer was opened via emacsclient, which sounds like what you really want.
Edit:
I'm not really happy with this, but it seems to work:
(global-set-key (kbd "C-x k") (lambda () (interactive) (server-kill-buffer (current-buffer))))
Okay, THIS did work for me:
(global-set-key (kbd "C-x k") '(lambda ()
(interactive)
(if server-buffer-clients
(server-done)
(kill-this-buffer))))
(this is the code from IvanAndrus's answer with the explicit changes from edits and comments, and using jrockway's keybinding.)
And, yes -- I am rebinding a standard keybinding. BUT it's a functional replacement NOT something completely different (eg, replacing kill-ring-save with kill-buffer stuff).
BTW, EmacsWiki has a couple of pages on this topic-- KillKey and KillingBuffer -- neither of which shed better light for me than the above (although the first-function on KillKey also used "server-edit"...).
I am not sure if that will work on windows, but on linux, emacs -daemon is just great.
With it, you don't have to run a different program, and your bindings are the same. I guess there are other advantages, but since I could never learn those emacsclient bindings, I never really used it, and can't say.
I don't think -daemon had been released yet, I am using 23.0.60.1 from CVS.