For very many reference files, I am rather addicted to the combination of hi-lock, text-mode, and the very plain utility of TABs.
Here is a simple example. The file
hi-lock: (("===^^^===" (0 (quote compilation-line-number) t)))
hi-lock: (("http.?://.*" (0 (quote browse-url-button) t)))
===^^^===
===^^^===
Flutter Navigation
Routes and Navigation
Navigator https://api.flutter.dev/flutter/widgets/Navigator-class.html
Named Routes https://docs.flutter.dev/cookbook/navigation/named-routes
===^^^===
etc..
===^^^===
renders as follows.
This works nicely.
I can insert lines to highlight the divisions between sections.
I see HTTP links clearly highlighted (even if I still need to cut-and-paste to access them).
The TABs, as mentioned, provide adequate "section" and "subsection" semantics.
It's just text. This is not a trivial advantage, because my OS (macOS) indexes .txt files. There might be a way to nudge it to index other extensions. Still, the commands of any other file formats (as with, notably, LaTeX) will get in the way.
But there are also several problems.
I need to manually maintain (an otherwise unnecessary) hi-lock header for each file.
I need to maintain regular expressions (though this can be fun for tricky cases).
The semantics of hi-lock are dubious. (Why is compilation-line-number chosen for a separating line?)
Maintaining a reasonable color scheme becomes difficult after a few colors.
Maintaining indentation with TABs is laborious (as you can see from the misalignment of the URLs).
Does org-mode solve these problems while maintaining the advantages of text-mode and hi-lock?
If you're comfortable with ORG, I would particularly like to see how the snippet above can be rendered in an equally—or better—looking way using ORG.
Related:
Compare markdown or org mode
The spirit of the question is:
I couldn't be bothered to write configurations so frequently.
I'm seeking the largest signal-to-noise ratio.
The following is a remedy (working) solution, on the path to migrating to org-mode from a combination of text-mode and hi-lock.
Using the following .emacs file.
(add-to-list 'default-frame-alist '(background-color . "black"))
(add-to-list 'default-frame-alist '(foreground-color . "white"))
(set-frame-font "-*-*-medium-r-normal--24-*-*-*-*-*-*-*")
(setq org-startup-indented t)
(require 'org-superstar)
(add-hook 'org-mode-hook (lambda () (org-superstar-mode 1)))
The following lines
* Flutter Navigation
** Routes and Navigation
- Navigator https://api.flutter.dev/flutter/widgets/Navigator-class.html
- Named Routes https://docs.flutter.dev/cookbook/navigation/named-routes
* etc..
render as follows.
Though this addresses neither the separating lines nor the tabs.
Separating lines are easy, if they're meant for the output (PDF, etc) rather for the Emacs display itself.
Also...
Open URLs with the system-wide browser (
1,
2).
Related
There are multiple questions along these lines but I haven't been able to find what I need from start to finish. I have been using emacs for a few years but am not used to its customization.
I have a unique file type, identified by its extension, which emacs is not configured for. Its comment style is
<!-- text -->
and I would like to set the variables comment-start and comment-end to the relevant values (which I am assuming will allow me to use comment-region). I don't know the correct way to do this so that it will always be configured when I open this file type but won't affect the default behavior of emacs.
Do I need to make a new major mode for this file type, and then set the variables, or is there an easier way of doing it? An example of the complete requirements for my .emacs file would be much appreciated!
See here. I think this will work:
(add-to-list 'auto-mode-alist
'("\\.extension\\'" . (lambda ()
(setq-local comment-start "<!--")
(setq-local comment-end "-->"))))
Alternatively, if this file extension is well known (or if these files are close enough to a well known syntax), you may be able to just find a major-mode online that does what you want. For example, NXML Mode may just give you the comment syntax you want along with some other useful features.
I have to adjust to 4 space indentation for a project I'm collaborating on at work. I hate looking at it, being accustomed to a nice compact 2 space indentation. Is there any way to have emacs display 2 spaces as one? Or maybe tabify on file load, and untabify on save. I'm working in c++. I have searched through google, but can't seem to find an answer to this.
You can try using prettify-symbols-mode, which is built into Emacs >=24.5.
(defun jpk/contract-spaces ()
(add-to-list 'prettify-symbols-alist '(" " . ?\ ))
(prettify-symbols-mode 1))
(add-hook 'c-mode-common-hook 'jpk/c-contract-spaces)
This changes the display, not the content of the buffer or file. I'm not sure this is the best idea. It will affect (auto)indentation and you won't see what the saved file will look like.
I would like to setup a personal wiki in org-mode.
So far, I have tried this two ways. My first attempt was using a single "Scientific Notebook.org" file. In this went all my notes - each with its own headline, date and tags (same format as a blog post). I then turned on org-velocity to quickly navigate the file.
But this created two problems: first, I use a lot of math in my notes (LaTeX previews are one of the reasons I want to us org). But these take sooooo long to load, I can't images trying to open a file with several thousand entries (all filled with math!!)
The other problem I have is with tags. I like to use a lot of multi-word tags to cross-reference my notes. But the way org-mode wraps these in the buffer, makes my headings completely unintelligible. Also (maybe it's just me but) I find CamelCase really hard to read, especially when faced with something like:
:monotonicTransformations:homogeneousFunctions:orderedSets:proofs:
Now my second attempt is with Deft. Here, I have broken up each note into its own .org file and creating a dedicated ~/org/ folder to hold my wiki. But this is where I am stuck:
1) How do you setup auto linking, so that typing say "foo bar" in one note, creates a link to "foo bar.org"? Can this be done with radio target? If not, can this syntax [[foo bar]] be overridden to search for headlines in all files in the ~/org/ directory? I tried adding Wiki.el as a minor mode but no dice...
2) How do you tag individual files? And how can you then pull up a list of all tags and use this to filter your list of notes? I have read that bookmark+ lets you do file tagging. But I got so lost in the online docs...
I would love to hear how others have solved these problem, what minor modes you are using, workflows and keyboard shortcuts or other mods!
Thanks!
-Adam
I'm using a simplistic code for a wiki.
Because that's what a wiki is for me: a quick way to categorize things.
The structure is a following:
each subject has its own org file
each topic of subject has its own heading
all org files are in single directory
you can jump to file, or create a new file with helm
That's it. I've found to need to link anything to anything, jump-to-subject functionality
is more than enough. Here's how this looks:
And once within a subject, I can jump across topics with worf.
Here's how this looks:
Having only one note file is, in my opinion, more flexible and compatible. It tends, however, to get slow for even moderatly sized files. Multiple small files are quick, but they need more effort to set up, and they only work within that setup.
Single File Solution
To speed things up, consider setting org-startup-with-latex-preview to nil (or add #+STARTUP: nolatexpreview to your file).
Tags not only get messy when used for keywords, using them also gets rather slow as your file grows. I've played around with some custom functions, but now avoid tags most of the time. Instead I use flat hierarchies, categories and otherwise rely on occur and org-occur (e.g. M-x org-occur begin_proof).
Multiple Files
The org syntax for linking to other files is rather simple: [[./this idea.org][this idea]]. If that is too much hassle, it should be easy to write a function that replaces the active region with an appropriate link.
If you want to link [[this idea]] to a file "this idea.org", you could add a function to org-open-at-point-functions and handle it yourself.
As for tags, you don't tag a file itself, but rather a single top level headline. This of course means that all your troubles with tags a back as well.
Again, I would recommend not using tags. Just make sure the file contains the right keywords at the right places and use occur and friends.
Edit: An Example `org-open-at-point-function'
If you want to search for a fuzzy link in all files in a directory instead of only the current buffer, you can do this by using the org-open-at-point-functions hook. Here is an example:
(defvar my-link-search-directory "/my/notes/directory/")
(defun my-open-link-function ()
"Open link, interpreting it a the name of a headline."
(let* ((el (org-element-context))
(type (first el))
(link-type (plist-get (cadr el) :type))
(path (let ((path-1 (plist-get (cadr el) :path)))
(when (stringp path-1)
(org-link-unescape path-1)))))
(when (and (eql type 'link)
path
(string= link-type "fuzzy"))
(let* ((path (regexp-quote path))
(result
(delq nil
(org-map-entries
(lambda ()
(when (string-match
path
(org-get-heading))
(list (buffer-file-name) (point))))
nil
;; Here we set the scope.
;; 'agenda would search in all agenda files.
;; We want a list of all org files in `my-link-search-directory'.
(directory-files
my-link-search-directory
t "[.]org\\'")))))
(when result
(when (> (length result) 1)
(message "Warning: multiple search results for %s" path))
(let ((file (caar result))
(pos (cadar result)))
(find-file file)
(goto-char pos)))))))
(add-hook
'org-open-at-point-functions
'my-open-link-function)
Note that I haven't tested this much.
Actually, I would recommend against using this unless you really need it. While making fancy extensions is tempting, keeping your notes as simple as possible is preferably. If you have everything in one file, you could edit your notes with notepad or google docs or whatever, should you ever need to.
I recently learned the basics of emacs' org-mode and couldn't help but imagine applying the collapse/expand concept to parts of a source file. I would like to be able to divide my .emacs file in subparts and only display headers on load, somewhat like the following:
; ERC config...
; DIRED config...
; MISC config...
Each of these would of course be headers to many lines of codes once expanded, like this:
; ERC config
(defun start-irc ()
(interactive)
(erc-tls :server "irc.freenode.net" :port 6697 :nick "foo"))
; DIRED config...
; MISC config...
So is this possible? How could I accomplish something like this with emacs 24.2?
Thanks!
As nice as org-mode is, it does require some structure, which I don't believe can be maintained the way you want in your .emacs file.
What does work well is folding-mode. Check out the information for it on the wiki page, but basically what you do is set up comments around the chunks of code you want to put in a fold, like so:
;;{{{ some folder of some kind
(a few lines)
(of lisp)
(this "code" is just filler)
;;}}}
;;{{{ a different folder
(some more elisp code)
;;}}}
And when it is folded, it will look like:
;;{{{ some folder of some kind...
;;{{{ a different folder...
Babel enables you to achieve exactly this (i.e. managing your init file in org-mode). Specifically, see: http://orgmode.org/worg/org-contrib/babel/intro.html#emacs-initialization
Myself, I make use of outline-minor-mode in my init file for vaguely similar purposes. Various things are treated as outline headings, but you can set outline-regexp as a file local variable to restrict that behaviour, and then you toggle things open and closed with outline-toggle-children (which you would bind to some convenient key). The toggle command works from anywhere in the section, not just on the heading.
I start the headings I want to be collapsed by default with ;;;; * and end my init file with:
;;; Local Variables:
;;; outline-regexp: ";;;; "
;;; eval:(progn (outline-minor-mode 1) (while (re-search-forward "^;;;; \\* " nil t) (outline-toggle-children)))
;;; End:
In your instance you could use:
;;; Local Variables:
;;; outline-regexp: "; "
;;; eval:(progn (outline-minor-mode 1) (hide-body))
;;; End:
Pretty similar in effect to Trey's suggestion, although I expect with folding you can trivially nest sections which I'm not accounting for (having no need to do so). I feel the outline approach leaves the file looking slightly cleaner, if that matters to you.
You can also take a look at the new Outshine package which works together with outline-minor-mode to make it feel more like org-mode. In (e)lisp files outshine interprets sequences of semicolons as headers so all existing code which follows standard conventions for comments becomes foldable without any changes. Many org-mode-like key bindings (like TAB to fold/unfold heading, etc) work too.
I'm updating some fortran 77 code to use fortran 90 constructs and emacs is my editor of choice. Currently, the source is in fixed format and that isn't going to change any time soon (due to external constraints). The two emacs major modes that I can choose from are fortran-mode which only highlights the syntax for fortran 77 constructs (It doesn't understand module or contains, etc. as keywords which I find pretty annoying, but it does understand fixed format -- correctly indenting the code where necessary). The other major mode I could use is f90-mode, however, that gets the indentation all wrong which is also slightly annoying. Is there any way to get the syntax highlighting from f90-mode, but the indentation structure used in fortran-mode?
It looks like this is indeed possible. Try adding the following to your config file:
(require 'f90)
(add-hook 'fortran-mode-hook 'f90-font-lock-2)
This is just following the solution provided on emacs.stackexchange.com, so thanks should flow to user deprecated!
You can achieve some fortran90 like highlighting in fortran-mode by adding
(add-hook 'after-change-major-mode-hook
(lambda () (font-lock-add-keywords 'fortran-mode
'(
("\\(CONTAINS\\)" 1 font-lock-keyword-face t )
("\\(USE\\)" 1 font-lock-keyword-face t )
))))
to your ~/.emacs (or ~/.emacs.d/init.el) file.
For a comprehensive solution some additional work with regular expressions would be needed. But with a few lines, you should be able to feel comfortable with your code. Different colors can be gained by using different faces:
font-lock-comment-face
font-lock-constant-face
font-lock-function-name-face
font-lock-keyword-face
font-lock-type-face
font-lock-warning-face