How can I treat certain patterns as web-site links, that can be followed with org-open-at-point? - emacs

At work I frequently deal with support issues that my company keeps track of in a web-based bug tracker.
Each issue has an URL that looks like https://mycompany.com/support/SUPPORT-12345, but of course I don't want to spell this out every time I mention a support issue in my Org-mode file. I would like set up Org-mode in such a way that the pattern SUPPORT-(\d+) is treated as a hyperlink to https://mycompany.com/support/SUPPORT-\1.
I would like to be able to place my cursor over the SUPPORT-2345, type C-c C-o, and have Emacs point my browser to https://mycompany.com/support/SUPPORT-2345. Ideally, SUPPORT-2345 would behave no different than a hyperlink.
Can Org-mode be configured in this way? If not, what is the best alternative?

You should be able to do this with org-link-abbrev-alist. For example, see the below for some I use. You can then put [[Support:1234]] in your Org-mode file and have it treated as the expanded link.
(setq org-link-abbrev-alist
'(
("DOI" . "http://dx.doi.org/")
("FreshDesk" . "https://xyz.freshdesk.com/support/tickets/")
("JIRA" . "https://jira.apps.monash.edu/browse/")
("Support" . "https://support.xyz.com/helpdesk/tickets/")
("ISBN" . "http://isbn.nu/")))

I don't know whether Org-mode have this feature, but there is a bug-reference-mode for it.
Here is sample org file:
;; Local Variables:
;; eval: (bug-reference-mode)
;; bug-reference-bug-regexp: "\\(\\(?:\\(?:SUPPORT\\|support\\)-\\)\\([0-9]+\\)\\)"
;; bug-reference-url-format: "https://mycompany.com/support/SUPPORT-%s"
;; End:
* SUPPORT-123
* support-1234
And you can move point on support-* and press C-c RET (bug-reference-push-button) to open it.
For more detail about Bug Reference, please refer to C-h r g Bug Reference

Related

How can I define auto-indent and auto-pairing in .emacs file for emacs 24.3.1?

Just FYI, I am new to the .emacs file.
I would lik to set up my .emacs file to auto-indent and auto-pair a certain way to make writing code a little faster. I have found some info as to how to do these things independently but I'm not sure how to put it all together for the emacs version that I have. Ultimately, I would like to set up these definitions specific to which ever language I am coding in. Just to get me started I will use java as an example.
Obviously auto-pairing for ", (, ' are pretty straigforward. I would just like it to auto insert a closing ", ), ' and place the cursor in the middle.
For {, I would like it auto insert two newlines and the closing } whith the cursor in the middle.
Example
while (true) {
<--- cursor would be here with auto-indent of 2 spaces
}
I would also like this to work for nested curly braces which the appropriate indentation.
Example
while(true) {
if (...) {
}
}
Here is what I have so far in my .emacs file:
(defun java-autoindent ()
(when (and (eq major-mode 'java-mode) (looking-back "[{;]"))
(newline-and-indent)))
(add-hook 'post-self-insert-hook 'java-autoindent)
Obviously this just inserts a line and auto indents, but I also want the closed } to be included on the line below. I also tried using electric-pair but that didn't work.
My wish list may be a little unrealistic. I'm not even sure that this is possible, but I would be happy with the closest that I could get.
Any help to get me going in the right direction would be greatly appreciated.
Emacs defines modes for each type of language you code in. Some modes are derived from others and there is a mode called prog-mode which most programming modes are derived from.
The mode for a language is where things like indentation are defined because these tend to be language specific. The rules for indentation can be quite complicated, which is why people often use a mode with similar indentation style as the parent and derive a new mode from that.
Have a look at modes and derived mode in the emacs elisp manual.
With respect to adding matching/closing delimiters, have a look at electric-pair-mode (I think it was in emacs 24.4 - I'm running 25 and forget when it was introduced).
With respect to your requirement to enter some code, some newlines and position the cursor in a specific place, you probably want to look at one of emacs' template solutions. yasnippet is a popular choice and it is easy to define new templates in it. There are also many existing packaged yasnippet templates you can download/install. If you don't like yasnippet, google emacs template and have a look there are quitre a few frameworks.

Buffer menu to select a set of filenames in Emacs

I have a directory "a" with a set of templates, for instance
$ ls a
b bcc cc ccdd
I would like to implement a keyboard shortcut in Emacs that will show a buffer with the template names, similar to dired or buffer-menu and then be able to select a template name by using arrow keys or mouse. Then insert the selected template into the current buffer at point.
How can this be done?
To augment Chris' answer with a little code, here is a small wrapper around ido-insert-file:
(require 'ido)
(defvar so/template-directory "/tmp/templates"
"Directory where template files are stored")
(defun so/insert-template ()
(interactive)
(let ((default-directory so/template-directory))
(ido-insert-file)))
This allows you to run (or bind a key to) so/insert-template no matter what directory you are currently in. Obviously set so/template-directory to your preferred directory.
insert-file, bound to C-x i by default, can insert a file into your buffer at point, but it doesn't give you a nice menu. Both helm and ido enhance this behaviour.
helm does not come with Emacs, but it can be installed via MELPA. When helm-mode is active, insert-file uses Helm's narrowing features. Once you're in the a directory, the up and down keys may be used to select a file, and Enter will insert it.
ido is shipped with Emacs. When ido-mode is active, C-x i is rebound to ido-insert-file. Once you're in the a directory, the left and right keys may be used to select a file, and Enter will insert it.
Both tools are excellent, both can be used in many other situations, and both offer effective filtering and navigation. Try one or both and use whichever you prefer.
Everything #Chris said about Helm and Ido is true also for Icicles, and with better "narrowing" features and on-the-fly sorting in different orders.
There is nothing extra to do --- just load Icicles and turn on Icicle minor mode. Whenever you use standard command insert-file (bound to C-x i) you get the behavior you requested for free. This behavior is in fact available for all completion in Emacs. In Icicle mode, standard commands become menus you can use the arrow keys on, etc.
In addition, your question title asks to be able to "select a set" of files. You can do that easily in Icicles, but not otherwise. IOW, selection is also multi-selection.
(However, I suspect that your question is mistitled, since the text describes something different, and I doubt that you want to insert a set of files. You probably meant that you want to select one file name from a set of file names. Consider retitling the question, if so.)

The equivalent of a GUI "Quick Open" in Emacs on CLI?

The title probably doesn't describe this question well enough. Many GUI-based editors allow you to press a key combination and then start typing a file name (anywhere, in any directory) and as you're typing, a list is filtered down of all the files matching that pattern, in realtime. If you hit enter, the currently highlighted file will be opened, or if you hit the UP or DOWN arrows you can change the selection. For example, in TextMate and Sublime Text 2 (on OS X) this is achieved by hitting CMD+T.
Now I know about find-dired and find-grep in Emacs, but is there anything else available that's a little more instant? The annoying thing with dired is that you have to hit enter and perform the search in order to see if the filename was correct. This is ok if you know the filename, but not so good when you're going based on educated guesses. It seems like something emacs could be suited to. Set the directory to index (just once) then when searching filter the index using a Radix tree search or some such, using a split window to show files and responding to the UP and DOWN arrows to adjust the selection.
Anything out there? :)
ido-mode is perfect for this. It has countless useful applications, including fuzzy filename matching as you demonstrated in your picture.
Some things to get started:
What You Can Learn From ido-mode
EmacsWiki article
Introduction to Ido Mode
Anything.el does this with files and it can do much more. Here's a good introduction on how to use it.
ido-mode is great on its own, but you may find the likes of Find File In Project a better option for matching filename patterns anywhere within a directory tree.
M-x find-file-in-project RET chooses the root of the directory tree automatically (based on the directory-local variables file).
I'm just now noticing that the M-x ffip-find-file-in-dirtree RET which I also have available (and which works on arbitrary specified directory trees, irrespective of project files) is actually provided by the ffip.el included with nxhtml.
The latter also looks like it supports ido when it's enabled. (Actually, there's a bug, but change (if (memq ido-mode '(file 'both)) to (if (memq ido-mode (list 'file 'both)) in (defun ffip-find-file-in-project (file) ...)
There will doubtless be a variety of similar options available.
peepopen also provides this functionality
I found it where I didn't want to :( ...
A plugin, called "Control-P" for vim - provides the exact same functionality the author of the question is looking for.
For example - on this video - http://www.youtube.com/watch?v=YhqsjUUHj6g - go to 26:55, and there you'll find a quick and very clean example of it. So, with one command you point to the doc-root, and after that - you're good to go :) ...
Unfortunately, none of these work the same way :D ...
I've used "Sublime text 2" for a long time TOO ... and yesterday decided to try using "emacs" ("vim" is very uncomfortable). So, I wanted this functionality:
You point to the root folder of a project.
And voila - you have "quick-find" functionality.
But ... there is no such functionality :( ...
(for example - "find-file-in-project" - it requires you to set-up "a file" in the root directory of the project, so it will know that it's the root of your project ... but what if I have to work on several projects simultaneously? ... some of them - use git, some of them - SVN, and some of them - none of these ... :D ... "Sublime text" handle this situation on-the-fly ... but emacs and vim - no :( ...)
Still waiting for the answer though ...

Suggestion for \cite in Emacs with AUCTeX

I would like to know how can I get the suggestion when I do a \cite in Emacs-AUCTeX. The minibuffer tells me when I do C-c [ that:
No valid bibliography in this document, and no default available
So how can I set this default? I have a separated file with my bibtex references that is called by a master document, and I want the suggestion for any of the other files included.
Have you tried: Ref -> Parse Dokument -> Entire Document? That solved the problem for me.
The variable reftex-default-bibliography is what defines the default bibliography to use. I don't do much with mult-file documents, do you have reftex-plug-into-AUCTeX turned on?
Yes, modifying this variable is a solution (I don't know if it is the "best solution"). I go to the ref menu -> Customize -> Browse Reftex Group -> Reftex Citacion Support -> Reftex Default Bibliography and then I add the path to the bib file (without the .bib extension) and it works!! These options create this in the init file:
(custom-set-variables
'(reftex-default-bibliography (quote ("D:/mybibdirectory/mybibfile"))))
(custom-set-faces
)
Well, perhaps that it works now that suggestions are going to appear in every document that I write. It would be good have a solution only for this document.
Reading the help file of reftex (reftex->finding files) also mentions make the next modifications in order to get the suggestions:
(setq reftex-bibpath-environment-variables
'("D:/mybibdirectory/"))
You may also try the solution mentioned in Re: auctex - no valid bibliography?. It worked for me.
(It might help to check whether you have kpsewhich installed, before attempting to use this fix. The following command should output its path if you do have it installed:
$ which kpsewhich
)
When in the buffer of your non-master file, try to query for the name of a master file (again) with C-c _ (Control C + underscore) as explained in auctex manual
This will add the local variable TeX-master to the end of your file. Save your file, restart emacs and load your file again. Hopefully, you can now get references from the bibliography stated in your master file by calling C-c [ in the subfile.
Mysteriously, when I do this manually without letting auctex query for it, it does not work. I cannot see how the end result is different in the auto directory either. But somehow letting auctex query for the value made it work for me.

Emacs how to auto-complete words of include files on C?

How can I make Emacs to complete words that are in C include files ?
#include <stdio.h>
int main(){
print//<-- this is where I want it to complete printf
What's the simplest way? (something simpler than Cedet)
First generate tags for the source and include files you'd like to be able to autocomplete for. See my blogpost for tips on using tags if you didn't use tag tables before.
Now if you have a TAGS table that includes the stdio.h, then you can autocomplete 'printf' using the command `complete-tag'.
Perhaps bind `complete-tag' to a key:
(global-set-key [f3] 'complete-tag)
Unlike complete-tag, dabbrev-expand, or hippie-expand (which does dabbrev-expand like things), the CEDET suite does exactly what the question describes. When asked to perform a completion, it looks and sees that you have included stdio.h, and then looks there for possible completions.
CEDET does a lot of other things related to completion as well which will provide very focused and correct suggestions, not just vaguely similar suggestions. A side affect is that CEDET takes more effort to setup. You need to teach it where you include files are, for example, and sometimes how to deal with macros, and what the project you are working on is like.
There is more detail on this here:
link text
You might want to try out M-/ (dabbrev-expand). This command attempts to complete the identifier immediately preceding the point (ie, where your cursor is) using the contents of the current buffer and then the contents of other buffers of the same mode. If the first completion offered isn't the one you want, just keep typing M-/. If you have the habit of keeping a single emacs session open continuously (which, if you don't have, you should really acquire), and have a handful of files from the current project open, you're quite likely to be able to find an the expansion you want for any particular prefix.
So, to answer you're original question, M-/ will find the printf completion you're looking for if (a) you've used printf anywhere else in the buffer you're editing, or (b) it appears in any other .c or .h file you have open in emacs.
You might also try hippie-expand, which has additional options regarding where it looks for completion information. I bind M-/ to hippie-expand, and then modified the order of the elements in hippie-expand-try-functions-list as follows:
(global-set-key (kbd "M-/") 'hippie-expand)
(setq hippie-expand-try-functions-list '(try-expand-dabbrev try-expand-dabbrev-all-buffers try-expand-dabbrev-from-kill try-complete-file-name-partially try-complete-file-name try-expand-all-abbrevs try-expand-list try-expand-line try-complete-lisp-symbol-partially try-complete-lisp-symbol))
This makes hippie-expand act like the normal M-/ at first, but repeated presses will yield more possible expansions.