perltidy-mode autorun in Emacs - emacs

I have a perltidy-mode.el lisp file, which is being loaded - I can call it manually by M-x perltidy-mode.
What would be the proper way to run it automatically after a file is opened (or emacs is loaded)?
(defalias 'perl-mode 'cperl-mode)
(defalias 'perl-mode 'perltidy-mode)
doesn't seem to work.
It seems I've forgotten a lot of lisp/emacs

If you would like to activate it for every opened perl file, you can add it to a hook:
(defun my-perl-hook ()
(perltidy-mode 1))
(add-hook 'perl-mode-hook 'my-perl-hook)
Note: I know nothing about this mode, or about the different perl modes, so you might to add your function to other hooks as well.

Related

Make eshell tab completion behave like Bash

How can I make eshell autocomplete behave like Bash and Emacs in general i.e. it offers a list of choices rather than arbitrary selects one for you?
For example, if I have two directories "Download" and "Downloads", when I type "Down" and hit TAB, I expect another buffer pops up and shows me the choices. But eshell just completes it for me, i.e. if I press TAB, it completes to "Download"; hit TAB again, it changes to "Downloads".
Use this:
(add-hook
'eshell-mode-hook
(lambda ()
(setq pcomplete-cycle-completions nil)))
(add-hook
'eshell-mode-hook
(lambda ()
(setq pcomplete-cycle-completions nil)))
and
(setq eshell-cmpl-cycle-completions nil)
Both do as you ask and show a buffer listing the completions when I run my emacs as 'emacs -q' to avoid my own customizations. This is with emacs 23.3, are you running a much older version?
Also see http://www.emacswiki.org/emacs/EshellCompletion which is where I first went to check this out.
Steps to try this out:
Start emacs using 'emacs -q' as the command -- no other arguments.
Change to the *scratch* buffer
Paste or type in one of the above code snippets
Put your cursor at the end of the snippet and press 'C-e' to execute the code.
Start eshell
test
if neither one works, report back here with your version info and any other relevant details
You only need to have the following line:
(setq eshell-cmpl-cycle-completions nil)
eshell-mode automatically set pcomplete-cycle-completions to the value of eshell-cmpl-cycle-completions locally.

how do I run this Emacs M-x command "wg-update-workgroup" automatically before emacs closes?

I would like this to happen when I right click the launcher...icon..and select quit..and choose file exit. I would like this command to be run right before emacs exits....so when I right click the launcher icon and select quit then this command "wg-update-workgroup" is run then Emacs exits..I've tried learning about hooks but don't get how to add one....If someone can give me exact code I put into my initialization file I would be very grateful....tried binding a function to a key but get weird command p error.
Here's the code:
(add-hook 'kill-emacs-hook
(lambda ()
(wg-update-workgroup)))
UPD
It seems that the code isn't working for you since wg-update-workgroup needs an argument.
You have to test this yourself, since I don't really want to get familiar with the package.
Solution 1:
(add-hook 'kill-emacs-hook
(lambda ()
(wg-update-all-workgroups)))
Solution 2:
(add-hook 'kill-emacs-hook
(lambda ()
(call-interactively 'wg-update-workgroup)))
UPD: disregard everything from above:)
I'm pretty sure this is what you want:
(setq wg-query-for-save-on-emacs-exit nil)
(push (lambda()(or (ignore-errors
(wg-update-all-workgroups-and-save)) t))
kill-emacs-query-functions)
The first statement removes the extremely annoying y/n query about saving
workgroups on exit. The second statement saves everything unconditionally on exit.
Just to list my full configuration:
(require 'workgroups)
(workgroups-mode 1)
(setq wg-query-for-save-on-emacs-exit nil)
(wg-load "~/wg")
(push (lambda()(or (ignore-errors
(wg-update-all-workgroups-and-save)) t))
kill-emacs-query-functions)
You're right to be baffled. The issue is this: when Emacs begins exiting, workgroups.el cleans itself up earlier than 'kill-emacs-hook. What you want is this:
(add-hook 'kill-emacs-query-functions 'wg-update-all-workgroups)
The hook variable should then look something like this:
(wg-update-all-workgroups wg-emacs-exit-query)
I recommend using 'wg-update-all-workgroups rather than 'wg-update-workgroup if, like me, you have more than one workgroup saved in a given workgroups file.
IMO workgroups.el is the best Emacs session manager. Somebody new has just taken it over. I'm excited that a new version with even more features may be forthcoming:
https://github.com/pashinin/workgroups2/

How to Reload files upon save when using swank+leiningen+emacs

I'm looking to set up slime+lein-swank to reload source files referenced from the repl when i save the file. currently i do this:
edit file
save file
switch to repl
(use :reload-all 'com.package.namespace)
test stuff
I want to not have to remember to do step 4.
You can use SLIME's C-c C-k before switching to the REPL, for slime-compile-and-load-file. It will prompt you to save the file if you haven't already. When it's done, the things which you've redefined should be available at the SLIME REPL in their new versions. Then you could use C-c C-z to bring up the REPL (close it with C-x 0 when you don't need it anymore).
Setup a hook in .emacs:
(defun clojure-slime-maybe-compile-and-load-file ()
"Call function `slime-compile-and-load-file' if current buffer is connected to a swank server.
Meant to be used in `after-save-hook'."
(when (and (eq major-mode 'clojure-mode) (slime-connected-p))
(slime-compile-and-load-file)))
(add-hook 'after-save-hook 'clojure-slime-maybe-compile-and-load-file)
Like the previous answer I use those same keystrokes but record them into a macro and bind it to a key. That way it's just one keypress to save, compile and switch to the REPL. It ends up looking something like this:
(fset 'compile-and-goto-repl
"\C-x\C-s\C-c\C-k\C-c\C-z")
(global-set-key [f6] 'compile-and-goto-repl)

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

In Emacs, how do I figure out which package is loading tramp?

I have a strange interaction with tramp and cygwin-mount (I think: Emacs: Tab completion of file name appends an extra i:\cygwin). Because of this, I want to disable tramp. I'm unable to find anything in my .emacs which is loading tramp explicitly. I can see "Loading tramp..." when I hit a tab in the find-file minibuffer. I'd like to figure out what package is causing the loading of tramp and disable that. How do I go about doing this? I tried searching for (require 'tramp) but couldn't find anything interesting. The only other option I can think of is to comment out bits of my .emacs one-by-one and see which one works - but this is so brute-force, I'd like a cleverer (and easier) way.
What a great question! If only because I was not aware of the function (eval-after-load file form) which will enable you to write code like the following and put it in your .emacs file:
(eval-after-load "tramp"
'(debug))
Which will, in brute force form, vomit a backtrace in your window and reveal the offending library.
I think you'll find that tramp is turned on by default. If you do:
M-x customize-apropos
Customize (regexp): tramp
('Customize (regexp):' is the prompt from emacs) you'll see two variables listed (at least I do in emacs 23), something like:
If you set tramp-mode to 'off', save for future sessions, and restart emacs tramp should no longer be loaded. I believe you can just turning it off in the current session should allow you to test this, but this doesn't always work with customize variables, although it should do with something like tramp that is part of the standard emacs distribution.
I don't have emacs 22 installed any more, but something similar should work for that too.
I had a similar problem with tramp, when one day I found
"/C:\...\debuglog.txt" on my system.
Because of that file, auto-complete was invoking tramp each time
I entered "/". And tramp was of course giving an error.
auto-complete was calling
(expand-file-name ...)
which, because of the current file-name-handler-alist, was calling tramp.
My solution was:
(delete-if
(lambda (x)
(or (eq (cdr x) 'tramp-completion-file-name-handler)
(eq (cdr x) 'tramp-file-name-handler)))
file-name-handler-alist)
Instrument find-file for debugging and/or instrument your init file for debugging. Then you can step through the loading and see where the tramp stuff is loaded.