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

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)

Related

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.

Emacs Rename Variable

How do I rename a variable in emacs? Eclipse has a neat "rename" refactoring action which lets you rename a variable in a scoping-aware way, which can be much easier to use than doing localized replace-strings, especially if the variable name is a character like e. Does emacs have a similar functionality built in?
New Emacs has M-s . to select symbol under cursor, then you can C-M-% and it will use currently selected symbol to perform replacements. NOTE This is just plain string replacement, not like the IDE 'rename variable' feature.
iedit was made for this kind of thing.
You can use narrowing to only show part of a buffer, and search/replace will only operate in the narrowed region. For example, you could use C-x n d to narrow to the current function, or select the region you want and do C-x n n. Do your search/replace, then widen back with C-x n w. For a single letter variable like e, do a query-replace-regexp with C-M-% and use a regexp like \be\b so it will only work on individual e's instead of ones inside other words.
Edit: Just thought of another thing. If you select a region, search/replace only works in that area. So you could just select the scope you want to replace in, then do the query-replace-regexp thing.
With the advent of LSP support in Emacs the actual "rename" refactorings are finally becoming viable in addition to narrowing/iedit/multicursor etc options in other answers, dependent on what the underlying language servers support.
emacs-lsp package provides lsp-rename
eglot package provides eglot-rename
In Python, this is more or less doable with the Rope refactoring library, for which I advise to use emacs-traad, in MELPA (straightforward to install and easy to use).
After installation we have the function M-x traad-rename which renames a variable in the project.
Rope documentation
For simpler search&replace, we have the aforementioned Iedit and also Projectile's projectile-replace.
I'm not sure what your source code language is. Because you mentioned about Eclipse, I assume that it is Java. One option is to use tags-query-replace functionality. Use Excuberant Ctags with -e switch to generate etgas style tags and invoke tags-query-replace.
Since you asked for a Eclipse feature, Iedit wont cut it. Its not that smart, what if you got two variables with the same name on different scopes? It would change both of them. This does not happen on eclipse!
You will need language specific tool if you expect that kind of awareness.
With typescript you can use tide.
With golang you can use go-doctor.
Specifically with Java, I could not find anything, but I use meghanada, which is great. But refactoring is on its TODO list! You use also use emacs as a client for eclipse with eclim.
As well as considering the already-suggested iedit, you can also consider multiple-cursors package. Check out an article about it, with animation of the live edition.
(defun replace-var (new)
"Replace the variable on the cursor"
(interactive (list
(read-string (format "Rename %s to: " (thing-at-point 'symbol)))))
(let ((old (thing-at-point 'symbol)))
(mark-defun)
(replace-string old new)))
(defun replace-old-var (old new)
"Input the old and new name"
(interactive "sFrom: \nsTo: ")
(mark-defun)
(replace-string old new))
(global-set-key (kbd "C-c r o") 'replace-old-var)
(global-set-key (kbd "C-c r v") 'replace-var)

Force flyspell to go to the end of the word when autocorrecting word in Emacs

I have found it annoying that flyspell seems to stay in the middle of the word when you do flyspell-auto-correct-word command. Can this be changed to force it to go to the end of the word after running the command? It might be as simple as setting a key binding to auto-complete-word and then move-forward-word which I know how to do. But this won't work in all cases because sometimes it puts the cursor behind the word if the auto-complete word was smaller than the typed word. Any help on this would be great.
Try this code:
(eval-after-load "flyspell"
'(defun flyspell-ajust-cursor-point (save cursor-location old-max)
(when (not (looking-at "\\b"))
(forward-word))))
Tested with flyspell version 1.7k, and with the version shipped with Emacs 23.2.
I looked through the (defun flyspell-auto-correct-word ...) and I can't see any good hooks or other customization points there so I think your best bet is to use C-h f defadvice:
(defadvice flyspell-auto-correct-word (after flyspell-forward-word activate) (flyspell-goto-next-error))

How do I list all yanks in emacs?

Is there a way to list all the yanked text in Emacs? You can do it on Textmate with SPLAT+V.
Edit: I meant recently killed items, items that can be yanked.
The list of kills (i.e., the list of things you can yank) is called kill ring and stored in the variable kill-ring, so you can view it (in a not very nice way) with C-h v kill-ring RET.
The kill ring also appears in the menu, under “Edit / Paste from kill menu”. If you use a text mode Emacs or have turned the menu bar off, you can access the menu with M-x tmm-menubar (bound to M-`): type M-` e p followed by the first letter of the item you want to paste (if it's a letter and it's unique, otherwise whatever character is indicated). If you don't want to paste anything, type M-` e p C-g; the kills remain in the *Completions* buffer. The kill texts are displayed truncated to yank-menu-length characters.
To my knowledge, emacs doesn't support that feature out of the box.
If you're using a Debian or Ubuntu Linux distribution, you can install the emacs-goodies-el package, which contains a browse-kill-ring feature (bound to M-y by default).
Alternatively, you can use the browse-kill-ring ELisp package available here.
See also here for a nice article about this problem and other alternate solutions.
EmacsWiki has a satisfying list of solutions. A portable and intuitive solution uses the built-in popup.el to display a vertical list to choose from:
(global-set-key (kbd "C-c y") '(lambda ()
(interactive)
(popup-menu 'yank-menu)))
In Icicles you can see all of your kill-ring, and yank any entries in it using completion. By default, C-y is bound in Icicle mode to icicle-yank-maybe-completing.
That's the same as yank, unless you give it a negative prefix arg (e.g., C--). In that case, it lets you complete against the kill-ring. Completion can be prefix, apropos (substring, regexp), or fuzzy.
http://www.emacswiki.org/emacs/Icicles_-_Multi-Commands
councel-yank-pop wors well for me
especially with the binding suggested in
http://pragmaticemacs.com/emacs/counsel-yank-pop-with-a-tweak/
(use-package counsel
:bind
(("M-y" . counsel-yank-pop)
:map ivy-minibuffer-map
("M-y" . ivy-next-line)))
if you use helm, you may call the helm-show-kill-ring function.

How to check which Emacs I am using?

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?