Orgmode priorities: possible more than A B C? - emacs

Is it possible to have more than 3 priority statuses in Orgmode?
I'd like to have A B C and D.
Thank you.

This has been working for me with priorities ranging from A to J:
(setq org-enable-priority-commands t
org-highest-priority ?A
org-default-priority ?J
org-lowest-priority ?J
)
However, I nearly never make use of F,G,H,I,J ...
At the time being I use org 9.3.4.
It seems to work without the first line "org-enable-priority-commands t" as well.
So you could write:
(setq org-highest-priority ?A
org-default-priority ?B
org-lowest-priority ?D
)

You can change the number of priorities by customizing org-priority-highest and org-priority-lowest, and there is also org-priority-default.
Or you can set it on a per-file basis.
Check for more options in the documentation.

Related

How to highlight floating numbers and integers differently in .F90 files in Emacs?

How to highlight floating numbers and integers differently in .F90 files in Emacs? In my version 24.4.1, there is no difference between floating numbers and integers. How can I display them in different colors?
The default emacs fortran mode doesn't differentiate the font faces for floats and integers. However, you could use the highlight-numbers package (via M-x package-list-packages or https://github.com/Fanael/highlight-numbers).
Add the following to your .emacs to highlight floats (change the foreground and background colors as you see fit:
(add-hook 'fortran-mode-hook 'highlight-numbers-mode)
(add-hook 'after-init-hook
(lambda ()
(puthash 'fortran-mode
(rx (and symbol-start
(? "-")
(+ digit)
"."
(+ digit)
(*? any)
symbol-end))
highlight-numbers-modelist)
(set-face-attribute 'highlight-numbers-number nil
:foreground "gray60" :background "black")))
I posted this question two weeks ago. Now I have had my own solution. So, I am posting it here as a reference for others who might encountered the same.
First of all, I'd love to thank #Justin for answering before and suggesting the highlight-number-mode. His solution probably works. However, I have a slightly more complicated requirement, so I decided to do it differently.
Also, I'd have to admit that I'm a very beginner in programming. So, you might find some stupid lines in my codes. Feel free to let me know if you think there's a better way.
Here is my solution.
Install highlight-number-mode and parent-mode in emacs. (The second one is required by the first one.) In my case, they are installed under /~/.emcas.d/elpa/.
As far as I see, the original highlight-number-mode does not support f90-mode, and it highlights all numbers (eg. 2, 3.4, 8e-2) equally, by changing fond color. This does not meet my requirement. Specifically, I wish to highlight only floating numbers, and I denoting them either as 2. or .5 in my .f90 script. In Fortran 90, floats and integers have different division rules. So, I hope to visualize them differently in order to reduce the risk of introducing such bugs. Therefore, I changed the following part in the source code (highlight-numbers.el):
(defconst highlight-numbers-generic-regexp
(rx (or
"."
(? (and
symbol-start
digit
symbol-end)
"."
(* digit))))
"Generic regexp for number highlighting.
It is used when no mode-specific one is available.")
(defvar highlight-numbers-modelist
(copy-hash-table
(eval-when-compile
(let ((table (make-hash-table :test 'eq)))
(puthash 'f90-mode
(rx (or
"."
(? (and
symbol-start
(or (and (+ digit) (? (or "." "e" ".e" "E" ".E")) (+ digit))
(and (+ digit) (? (or "e-" ".e-" "E-" ".E-")) (+ digit))
(and (+ digit) "." (+ digit) (? (or "e" "E")) (+ digit))
(* digit))
symbol-end)
"."
(* digit))))
table)
If you compare the above code with the original one by Fanael Linithien, you will notice that I have added two ".". As Fanael said (in private discussions), this is probably due to that "." is taken as a punctuation in f90-mode in emacs. So, I have to modify the regexp and the table accordingly.
Once the above has been done, I put the line (add-hook 'f90-mode-hook 'highlight-numbers-mode) in my init.el to load this package via elpa.
Afterwards, the floats in my code will be highlighted, such as
example
And you can see the difference in floats and integers.
In the end, I'd add that I have been using this for quite a few days. No problems happen so far. So, I guess it is working! :)

Emacs-lisp: prettify-symbols-mode for LaTeX

I was trying to port over the "pretty entities" behaviour from org-mode to latex-mode using the Emacs builtin prettify-symbols-mode. This mode uses font-lock-mode to display character sequences in a buffer as a single (unicode) character. By default for instance emacs-lisp code
(lambda () t)
becomes
(λ () t)
It does however seem to require the character sequences to be separated by some characters, e.g. white-spaces. For instance in my setup, the replacement
\alpha \beta -> α β`
will work, but it will fail when the strings are not separated, e.g.
\alpha\beta -> \alphaβ
This is an issue specifically, because I wanted to use this prettification to make quantum mechanical equations more readable, where I e.g. the replacement like
|\psi\rangle -> |ψ⟩
Is it possible to avoid this delimiter-issue using prettify-symbols-mode? And if it is not, is it possible by using font-lock-mode on a lower level?
Here's the code that should do what you want:
(defvar pretty-alist
(cl-pairlis '("alpha" "beta" "gamma" "delta" "epsilon" "zeta" "eta"
"theta" "iota" "kappa" "lambda" "mu" "nu" "xi"
"omicron" "pi" "rho" "sigma_final" "sigma" "tau"
"upsilon" "phi" "chi" "psi" "omega")
(mapcar
(lambda (x) (make-char 'greek-iso8859-7 x))
(number-sequence 97 121))))
(add-to-list 'pretty-alist '("rangle" . ?\⟩))
(defun pretty-things ()
(mapc
(lambda (x)
(let ((word (car x))
(char (cdr x)))
(font-lock-add-keywords
nil
`((,(concat "\\(^\\|[^a-zA-Z0-9]\\)\\(" word "\\)[a-zA-Z]")
(0 (progn
(decompose-region (match-beginning 2) (match-end 2))
nil)))))
(font-lock-add-keywords
nil
`((,(concat "\\(^\\|[^a-zA-Z0-9]\\)\\(" word "\\)[^a-zA-Z]")
(0 (progn
(compose-region (1- (match-beginning 2)) (match-end 2)
,char)
nil)))))))
pretty-alist))
As you can see above, pretty-alist starts out with greek chars. Then I add
\rangle just to demonstrate how to add new things.
To enable it automatically, add it to the hook:
(add-hook 'LaTeX-mode-hook 'pretty-things)
I used the code from here as a starting
point, you can look there for a reference.
The code of prettify-symbols-mode derives from code developped for languages like Haskell and a few others, which don't use something like TeX's \. So you may indeed be in trouble. I suggest you M-x report-emacs-bug requesting prettify-symbol-mode be improved to support TeX-style syntax.
In the mean time, you'll have to "do it by hand" along the lines of what abo-abo suggests.
One note, tho: back in the days of Emacs-21, I ported X-Symbol to work on Emacs, specifically because I wanted to see such pretty things in LaTeX. Yet, I discovered that it was mostly useless to me. And I think it's even more the case now. Here's why:
You can just use an actual ψ character in your LaTeX code instead of \psi nowadays. So you don't need display tricks for it to look "right".
Rather than repeating |\psi\rangle I much prefer defining macros and then use \Qr{\Vangle} (where \Vangle turns into \psi ("V" stands for "metaVariable"), and \Qr wraps it in a braket) so I can easily tweak those macros and know that the document will stay consistent. At that point, pretty-display of \psi and \rangle is of no importance.

Emacs caps lock minor mode?

Is there a command in Emacs to turn on what might be described as "caps lock minor mode"? I'm looking to do something like M-x toggle-caps-mode, then every letter I type in the buffer is a capital letter until I do M-x toggle-caps-mode again.
Note: I'm NOT looking for directions on how to swap caps and control. In reality this is because I have already done that. I am generally quite happy with it, but occasionally I'm editing code where there are a bunch of constants that are in all caps, and it gets to be a strain holding down the shift key. I'm aware of the various upcase conversion functions; I'd rather not have to type the word, select it, then run upcase-region.
If it matters, I'm using Aquamacs 2.2 w/ Emacs 23.3.1.
You don't need to type the word then select it. If you want to upcase the last word, press M-b M-u or ESC b u. Ok, you'll need to press b several times if it's a word_with_underscores.
If you really want a caps lock minor mode, try John Paul Wallington's lockcaps.el.
You can try something like this:
(define-minor-mode caps-lock-mode
"caps-lock mode"
;; The initial value.
nil
;; The indicator for the mode line.
" CAPS-LOCK"
;; The minor mode bindings.
'(("a" . (lambda () (interactive) (insert-char ?A 1)))
("b" . (lambda () (interactive) (insert-char ?B 1)))
;;etc
("A" . (lambda () (interactive) (insert-char ?a 1)))
("B" . (lambda () (interactive) (insert-char ?b 1)))
;;etc
))

In Emacs can you evaluate an Emacs Lisp expression and replace it with the result?

For example if I have the text:
Sum of items is (+ 1 2 3)
I want to move to the end of the line, evaluate the expression and replace it with the result, so that it reads:
Sum of items is 6
With the cursor at the end of the line, C-u C-x C-e will insert the value of the preceding parenthesized expression into the buffer. You could do that, then manually back up and delete the original expression. If that's too much work, here's a command that evaluates the preceding expression and replaces it with its value:
(defun replace-last-sexp ()
(interactive)
(let ((value (eval (preceding-sexp))))
(kill-sexp -1)
(insert (format "%S" value))))
Related to this, you might like Luke Gorrie's "lively.el", which provides live replacement of emacs lisp expressions within a text buffer. It's a neat hack.
I was having a go at a solution for this when I came across one in a Google search result.
(defun fc-eval-and-replace ()
"Replace the preceding sexp with its value."
(interactive)
(backward-kill-sexp)
(prin1 (eval (read (current-kill 0)))
(current-buffer)))
http://emacs.wordpress.com/2007/01/17/eval-and-replace-anywhere/
replace-regex functions can execute lisp to generate the replacements.
In the trivial instance where the sexp in question is on a single line, and is the only thing containing parenthesis, then you could match "(.+)" and replace with "\,(eval (read \&))".
If you are using emacs starter kit by technomancy there is "esk-eval-and-replace" function which evaluates the elisp sexp and replace them. Its bind to C-c e by default.
look to the function eval-print-last-sexp, you can build something using it
My emacs-fu isn't so strong, so I don't know if there's a single command to do this, but you can make yourself a (somewhat fragile) macro for it ... drop these lines in your .emacs:
(fset 'eval-sexp-in-place
[?\M-x ?e ?v ?a ?l ?- ?p ?r ?i ?n tab return ?\M-^ ?\M-^ ?\C-\M-b ?\C-\M-k ?\C-d])
(global-set-key [(control x) (control a)] 'eval-sexp-in-place)
This works fine, but there's one issue with it: you need to be at the end of the sexp (i.e. after the last right paren) to get it to work.
Also, I picked a random unbound key (C-x C-a) -- feel free to change that to something more to your liking.

Changing Paredit Formatting

When using paredit in programming modes such as C, typing ( will insert a space before the paren when I'm trying to call a function, leaving me with:
foo ()
Is there a way to disable the insertion of the space without changing paredit's source?
Well, the way paredit appears to work is that it checks the syntax tables to see if you're inserting a pair right after a word/symbol/etc., in which case it forces a space to be inserted. You need to override that functionality - which can be done a number of different ways: advice, redefine the function determining space, changing the syntax table, etc.
I'd try the straight forward:
(defun paredit-space-for-delimiter-p (endp delimiter)
(and (not (if endp (eobp) (bobp)))
(memq (char-syntax (if endp (char-after) (char-before)))
(list ?\" ;; REMOVED ?w ?_
(let ((matching (matching-paren delimiter)))
(and matching (char-syntax matching)))))))
This will obviously apply to all places where you use paredit. If you want something more mode specific, you can add some conditions to that and statement (e.g. (and ... (memq major-mode '(c-mode lisp-mode)))).
So... I guess I did change the "source", but you can do the same thing with a piece of defadvice ... it's all elisp, so the difference is minimal. There doesn't appear to be a setting to control this type of behavior.
See paredit-space-for-delimiter-predicates
Well, Paredit is ideal for editing languages built of S-expressions. If you just like how it automatically inserts the closing paren, use feature skeleton-pair.
(setq skeleton-pair t)
(global-set-key "(" 'skeleton-pair-insert-maybe)