Disable Carbon Emacs scroll beep - emacs

I've been looking into adopting Carbon Emacs for use on my Mac, and the only stumbling block I've run into is the annoying scroll beep when you try to scroll past the end of the document. I've looked online but I can't seem to find what I should add to my .emacs that will stop it from beeping when scrolling. I don't want to silence it completely, just when scrolling. Any ideas?

(setq visible-bell t)
This makes emacs flash instead of beep.

Using the hints from the Emacs wiki AlarmBell page, this does it for me:
(defun my-bell-function ()
(unless (memq this-command
'(isearch-abort abort-recursive-edit exit-minibuffer
keyboard-quit mwheel-scroll down up next-line previous-line
backward-char forward-char))
(ding)))
(setq ring-bell-function 'my-bell-function)
If you don't know the name of a command, press C-h k then the key/action you would like to get the name of.

You will have to customize the ring-bell-function.
This page may provide hints:
http://www.emacswiki.org/emacs/AlarmBell

Between Stephen Hassard's answer and Kipton Barros' comment:
(setq ring-bell-function 'ignore)
seems to be the most concise, works on emacs 24.x, and answers the original question.

This seems to do the trick:
(setq ring-bell-function nil)

Related

function similar to other-buffer but with filtering

I'm looking for a way to include some filtering in the other-buffer method in emacs.
Currently calling other-buffer pulls up the last most recent buffer, but the problem with this is that buffers that get modified by external processes keep coming up as other-buffer. I would like to implement some sort of filtering in other-buffer.
Currently I use evil with C-^ bound to other-buffer, and I have some tail.el buffers active, and when I try to switch bufffers the tail buffers keep popping up.
Is there some alternative to other-buffer or could someone scratch up some code to implement this, Thanks.
What has worked for me is winner-mode - it's like an undo, but for window configurations.
Here's my setup:
(winner-mode)
(global-set-key (kbd "<f7>") 'winner-undo)
(global-set-key (kbd "C-<f7>") 'winner-redo)
Also I'd recommend other-window on some very cheap shortcut, since it's
a command that's used a lot.
I've put it on C-p, since I didn't appreciate the inconsistency
that one of the direction keys is so far away from others.
I've got previous-line on C-h instead, so now
my direction keys are n h f b - they're almost together!
And I didn't really miss the defaults on C-h, since f1
has the same functionality.
Ok so I got some workable solution but its not perfect it using bits from this answer:
emacs lisp, how to get buffer major mode?
(defun buffer-mode (buffer-or-string)
"Returns the major mode associated with a buffer."
(with-current-buffer buffer-or-string (format "%s" major-mode)))
(defun other-buffer-ex ()
(interactive)
(switch-to-buffer
(if (string-equal (buffer-mode (other-buffer)) "comint-mode")
(next-buffer) (other-buffer))))

emacs ( recompile -y )

Is it possible to pass a "-yes" flag to the 'recompile' command in emacs?
Excuse my complete lack of (e)lisp know-how. I got sick of going outside Emacs to compile my latex code, so i added the following key binding to my .emacs:
(global-set-key (kbd "<f12>") 'recompile);
Is it possible to automatically answer 'yes' to the following prompt that might appear:
"A compilation process is running; kill it? (yes or no)."
Also, is it possible to make the window that opens and shows the output to scroll to the bottom automatically. The interesting stuff is typically down there. Maybe its possible to chain the following command after recompile: "C-x o, end-of-buffer".
Thanks!
Here's some code to solve your first problem (interrupting the current compilation):
(defun interrupt-and-recompile ()
"Interrupt old compilation, if any, and recompile."
(interactive)
(ignore-errors (kill-compilation))
(recompile))
For your second problem (scrolling the compilation output), just customize the user setting compilation-scroll-output.
This behaviour is governed by the compilation-always-kill global variable. Customize it via customize-variable and set it to t.
Not sure which version of emacs first had this, but 26 and newer certainly does.
I somehow need to put kill-compilation into a ignore-errors with Emacs 23.2 to get it to work when no process is running. Otherwise works great.
(defun interrupt-and-recompile ()
"Interrupt old compilation, if any, and recompile."
(interactive)
(ignore-errors
(kill-compilation))
(recompile)
)
Whenever I tried using kill-compilation with latex/pdflatex it did not work. I assume it is because latex does not respond to SIGINT.
Instead I am using the following hack, which first sets the process-kill-without-query bit of the compilation-buffer and then closes it (which kills the running process).
(defun interrupt-and-recompile ()
"Interrupt old compilation, if any, and recompile."
(interactive)
(ignore-errors
(process-kill-without-query
(get-buffer-process
(get-buffer "*compilation*"))))
(ignore-errors
(kill-buffer "*compilation*"))
(recompile)
)
The other solutions didn't work for me for the same reason as sfeuz, but I didn't like the nuclear option of killing the hardcoded buffer by name.
Here's a short solution that autoanswers yes to that specific question by advising yes-or-no-p:
ftp://download.tuxfamily.org/user42/compilation-always-kill.el
(source: http://www.emacswiki.org/CompilationMode)

Emacs - how do I automatically enter minor modes when I enter a major mode?

I'm kind of a newb when it comes to emacs. I know about the .emacs file but have very little idea as to do anything more advanced than elementary stuff.
Whenever I enter latex-mode, I'd also like to automatically turn on flyspell-mode, reftex-mode, auto-fill-mode, and also set fill-column to 120. How do I edit my .emacs file to do this?
Thanks!
(add-hook 'latex-mode-hook
(function (lambda ()
(flymake-mode)
(reftex-mode)
(auto-fill-mode)
(setq fill-column 120))))
for example should work.
You can set a so-called hook to a major mode. Have a look at this page of the manual for some examples.

How can I show the Org-mode agenda on Emacs start-up?

I would like the Org-mode agenda to automatically show what I have to do today when I open Emacs. The org-agenda command is interactive, so it doesn't seem to work well for this purpose.
Is there a way to show the Org-mode agenda on Emacs start-up?
Thanks,
Conor
You can use after-init-hook to run a piece of code after initialization has finished. To run (org-agenda-list) after init, use:
(add-hook 'after-init-hook 'org-agenda-list)
This works for me (in .emacs):
(setq inhibit-splash-screen t)
(org-agenda-list)
(delete-other-windows)
Without the first line, the splash screen "covered" the agenda; without the third one, the scratch buffer remained visible.
One alternative to the hook is to set the initial-buffer-choice variable. This is particularly useful if there are multiple buffers or a number of functions on the hook. The function on this variable needs to return a buffer. Naively this might be:
(setq initial-buffer-choice (lambda ()
(org-agenda-list 1)
(get-buffer "*Org Agenda*")))
Try (org-agenda-list). If you just want today, (org-agenda-list 1).
And of course, apropos is your friend. C-h C-a org-agenda (or whatever command) will show you useful info on that command.
I have a bash alias to start emacs with the Agenda open:
alias org='/usr/bin/emacs --funcall org-agenda-list &'
Enjoy.
It is not exactly at startup, but I keep Emacs running so I need a different approach
(require 'midnight)
(midnight-delay-set 'midnight-delay "7:30am")
(add-hook 'midnight-hook 'org-agenda-list)
Credits to https://stackoverflow.com/a/14947354/217408

How to accomplish equivalent of Vim's Ctrl-n in GNU Emacs?

Vim's Ctrl+N generally works like this: I type few letters, hit Ctrl+N, and Vim provides me with completions based on words in my all opened buffers.
Solution for Emacs doesn't have to be identical. I mainly use it like this: declare variable, then use it in later code. But I like the lightweight approach of not parsing the source code.
You want dabbrev-expand, bound to M-/ by default. I haven't used Vim, but from your description, it does the exact same thing.
try hippie-expand, bound to your favorite key
(global-set-key (kbd "M-/") 'hippie-expand)
Instead of presenting a completion-list, repeatedly hitting the bound-key cycles through the completions in-place.
Why "hippie"-expand? I have no idea, and I actually avoided looking at the function because the name was uninformative and off-putting, until I read the write-up at 'Life Is Too Short For Bad Code'. (The EmacsWiki entry on hippie-expand also asks "why 'hippie?'" but can't answer it, either.)
I personally use AutoComplete It gives you a nice dropdown box. You can select how many letters you want to type before it activates and customise what you want to show up, including stuff in dabbrev-expand.
;; Allow tab to autocomplete
(defun indent-or-expand (arg)
"Either indent according to mode, or expand the word preceding point."
(interactive "*P")
(if (and
(or (bobp) (= ?w (char-syntax (char-before))))
(or (eobp) (not (= ?w (char-syntax (char-after))))))
(dabbrev-expand arg)
(tab-to-tab-stop)))
(defun my-tab-fix ()
(local-set-key [tab] 'indent-or-expand))
(add-hook 'as-mode-hook 'my-tab-fix)
(add-hook 'java-mode-hook 'my-tab-fix)
(add-hook 'c-mode-hook 'my-tab-fix)
(add-hook 'sh-mode-hook 'my-tab-fix)
(add-hook 'emacs-lisp-mode-hook 'my-tab-fix)
The matter, in my opinion is that emacs completion I tryed doesn't complete regarding the context.
For instance, if you write some OOP with a method foobar() and an argument foo, M-/ will suggest you both foo and foobar.
But it would be great if you are calling an object method, not to provide just "foo" completion.
Has anyone a solution?
Aif> This requires much more than what "hippie expand" has to offer. If you code C/C++ you COULD use ECB http://ecb.sourceforge.net/ but frankly, the project is quite dead and this addon is not very reliable. If you need really good intelligent completion you should try Eclipse (CDT). But if you code python then Emacs (rope + flymake) is just as fine as Eclipse (PyDev).