In an answer, I noticed:
;; Align with spaces only
(defadvice align-regexp (around align-regexp-with-spaces)
"Never use tabs for alignment."
(let ((indent-tabs-mode nil))
ad-do-it))
(ad-activate 'align-regexp)
This sounds promising, but... what does it do?!
I tried eval-region on the block of code. But for me, all it does is adding the following to the align-regexp docs:
This function is advised.
Around-advice `align-regexp-with-spaces':
Never use tabs for alignment.
I don't seem to be able to actually use align-regexp-with-spaces, if that's what should be the effect... What am I missing?
I used GNU Emacs version 24.0.96.1 (i386-mingw-nt6.1.7601).
While asking this question, I realized that I just didn't get the idea of advising functions.
It became clear to me that:
align-regexp-with-spaces isn't a function nor a variable but only a name (to enable/disable single pieces of advice)
ever since (ad-activate 'align-regexp), align-regexp just does what I 'advised' it to: not to use tabs
So: ad-activate activates the advice, effectively changing the original function's behavior. Great!
I don't get why this is 'better' than defining a function around align-regexp though. But then again I don't know much about Emacs Lisp.
I'm afraid the extra lines of documentation only added to the confusion...
Related
I would like to use org-velocity as my primary means of navigating large .org files but with the following changes:
After running a search in org-velocity, I would like the buffer to automatically narrow to that subtree, once I make my selection.
Org-velocity should run its search against the entire file, even if the buffer is narrowed.
For part (1) I think something like this should work:
(add-hook 'org-follow-link-hook (lambda () (org-narrow-to-subtree)))
But this is not the right hook. Not sure how to approach (2). Any ideas? Thanks!
I am writing a partial answer for part (2) of the question since the following does not fit nicely into a comment. Note, that I do not use org-velocity. So, the following is not really tested.
save-restriction saves the current narrowing to the org-subtree and widen removes this narrowing temporarily during the search. To see exactly how it works read the help for the functions save-restriction and widen with C-h f and consult the info C-h i for elisp and there the Section "Advising functions".
(defadvice org-velocity (around search-all activate)
"Widen for search with org-velocity"
(save-restriction
(widen)
ad-do-it
))
Okay, I think I have a complete solution!
Make sure you have this fork of org-velocity installed:
https://github.com/Fuco1/org-velocity
Open your org-velocity.el file and replace lines 763-765 with this:
(progn
(with-current-buffer (org-velocity-match-buffer)
(kill-buffer-and-window))
(org-narrow-to-subtree)
(show-all))))))
The additional code tells org-velocity to first narrow the buffer to the selected subtree and secondly to expand that node.
Put this code somewhere in your search path (init.el, .emacs, etc.)
(defadvice org-velocity (around search-all activate)
"Widen for search with org-velocity"
(widen)
ad-do-it)
And that's it!
Thank you Tobias, Paul and Matúš for walking me through this!!
Take care,
-Adam
I would like to invoke M-x helm-swoop such that it does NOT return the symbol at point. I find that it always picks up undesired symbols, e.g. when I invoke M-x helm-swoop in org-mode, I get Swoop: \*, and I then have to delete the \* before I can enter my desired search term. How can I do this?
This has been bugging me as well, for exactly the same reason (swoop in an Org-mode buffer picking up heading characters), so this question motivated me to go and look.
Looking at the source, Helm-swoop calls helm-swoop-pre-input-function to populate the prompt, and by default this is set to a function that returns (thing-at-point 'symbol), which is what causes the problem in headings.
A quick test with the following in my init file seems to work:
(setq helm-swoop-pre-input-function
(lambda () nil))
This could certainly be improved by, for example, keeping the default behaviour in non-Org buffers but as I'm only really using swoop in Org buffers this is good enough for me.
Thanks to this post, I was able to remove some of the ugly underlining semantic utilizes with it's inline parsing, but I still have a hyphen appearing at each of my function calls (and sometimes else where) that I would really like to remove. How can I do this? I have also looked through http://www.gnu.org/software/emacs/manual/html_mono/semantic.html#Tag-Decoration-Mode.
Reference image:
I'd suggest looking at your CEDET config instead.
You're probably calling semantic-load-enable-excessive-code-helpers.
And this function got its name for a reason.
So instead of enabling a function that has excessive it its name,
and then trying to remove the excessive features, why not just stick with the basics?
Just to show you my CEDET setup:
(load "~/git/cedet/cedet-devel-load")
(add-to-list 'semantic-lex-c-preprocessor-symbol-file
"~/Software/deal.II/include/deal.II/base/config.h")
(semantic-add-system-include "~/Software/deal.II/include/" 'c++-mode)
(set-default 'semantic-case-fold t)
(semantic-mode 1)
But if there some extra cool functionality that
only semantic-load-enable-excessive-code-helpers provides, please let me know.
It turns out that the hyphen was part of the semantic tag folding mode, which functions to collapse and expand code blocks in the gui version of emacs. I am not sure the same functionality is achieved in the terminal interface; but regardless, to remove these hyphens from my code, all I had to do was turn off
(global-semantic-tag-folding-mode)
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))
For example, if I want to comment this:
(defun noop ()
nil)
Every time I try to put a semicolon before the "(defun", the defun runs away to the next line. So how is that supposed to be done?
GNU Emacs 23.1.1
Edit: by "running away" I mean when I insert a semicolon before "(defun", a newline is automatically inserted after the semicolon and "(defun" starts on a new line again.
See the command M-x comment-region and related.
M-X comment-dwim or M-;, which is the default key binding for the former — might save you a few key strokes, since it not only comments, but uncomments region, if it's commented already. Anyway, check out Emacs Manual for a proper description.
Ron, do a CTRL-H m and look at the minor modes. You have some "helpful" minor mode active. (Maybe paredit but I dont think that's it.) I remember there was something like that when I tried the EMACS Starter Kit. It lasted maybe thirty seconds before I screamed and found how to kill it.
In any case, that's not default EMACS behavior, it's some init-file or site-emacs addition.
Mark both lines and call M-x comment-region. Also look at comment-or-uncomment-region and comment-dwim functions.
For the specific task you asked for in the headline (commenting a complete expression that may span multiple lines at once), first press C-M-SPC (bound to mark-sexp) to set the region to the expression following point, and then M-; (bound to comment-dwim which will call comment-region).
If you're talking about Common Lisp (rather than, say, Emacs-Lisp), you can use #+(or):
#+(or)
(defun noop ()
nil)
See the CLHS for details.
a little late to the party, however, what about:
(defmacro comment (&rest a))
(defvar orgCmntEnd nil "Org Comment End")
(defun orgCmntBegin (<comment <commentEnd))
(orgCmntBegin "
** orgCmntBegin. Permits us to include * at the beginning of line as a comment.
Which in turn allows us to switch between emacs-major mode and org-mode for COMEEGA.
Example usage is:
(orgCmntBegin \"multi-line comment comes here.\" orgCmntEnd)
I wish elisp had a here-document facility. Like common-lisp.
Anybody listening?
" orgCmntEnd)