How to convert hex escaped characters to unicode characters? - emacs

I am revamping an old Emacs / Gnus configuration dating from before unicode Emacs (21.3 or 22). In this configuration, I was using some unicode characters to show usenet threads:
(setq gnus-sum-thread-tree-root "\x490a4 ") ; "> "
(setq gnus-sum-thread-tree-false-root "\x490a4 ") ; "> "
(setq gnus-sum-thread-tree-indent " ") ; " "
(setq gnus-sum-thread-tree-single-indent "") ; ""
(setq gnus-sum-thread-tree-leaf-with-other "\x4903c\x49020\x4904c\x490f9 ") ; "+-> "
(setq gnus-sum-thread-tree-vertical "\x49022 ") ; "| "
(setq gnus-sum-thread-tree-single-leaf "\x490b0\x49020\x490f9 ")) ; "\\-> "
But now with Emacs 23.2.1 I see empty squares instead of curved arrows. I suspect it can be either a fontset or an escaping problem related to unibyte / multibyte.
To exclude the escaping problem or solve it, how can I retrieve the unicode characters to use the \u1234 escaping instead of the \x12345 ? Thanks.
Edit: Thanks to an Emacs-22 I was able to insert those characters in a buffer and find their code with C-uC-x=.
The correspondance is
(setq gnus-sum-thread-tree-root "\u2564 "
gnus-sum-thread-tree-false-root "\u2564 "
gnus-sum-thread-tree-leaf-with-other "\u251c\u2500\u252c\25b9 "
gnus-sum-thread-tree-vertical "\u2502 "
gnus-sum-thread-tree-single-leaf "\u2570\u2500\u25b9 "))
...but the display is not as nice as it was at the time those unicode characters were chosen. It was on another system and I suppose that the font was nicer to display them.

I suggest you fire an older Emacs (Emacs-22), make it display those strings so you get to see those nice curved arrows and then copy&paste them with the mouse (no need to use the \uNNN notation).

In theory (decode-coding-string "\x490a4 " 'emacs-mule) should do what you want, but it doesn't seem to recognize that character, maybe because it was from an extension to MULE to support more Unicode characters.
I think the easiest solution will be to find visually the arrows you want, and replace those codes with their Unicode code points. See Arrows (Unicode block) in Wikipedia for a list of the potential candidates.

Related

How to get literal forward slashes in org-mode?

In text, can I make org-mode ignore forward slashes somehow? Phonetics uses /s/ to denote a certain level of analysis.
I assume that you do not want the text to appear emphasized in the buffer, nor in the output. This is a slightly more complex answer which will achieve that result:
There is a variable defined by Org-mode called org-emphasis-alist which defines the different emphasis modes, what their plain-text syntaxes are, and how they are exported to HTML. You can achieve the result you want by changing the value of this variable before Org-mode has been loaded. That last part is critical so note it well—Org-mode reads the value of org-emphasis-alist when it is loaded and uses that value to generate a regular expression for highlighting ("font-lock") purposes.
Here are two routes to that:
Add the following lines to your .emacs file above the lines that load Org-mode:
(setq org-emphasis-alist
`(("*" bold "<b>" "</b>")
;; ("/" italic "<i>" "</i>")
("_" underline "<span style=\"text-decoration:underline;\">" "</span>")
("=" org-code "<code>" "</code>" verbatim)
("~" org-verbatim "<code>" "</code>" verbatim)
("+" ,(if (featurep 'xemacs) 'org-table '(:strike-through t))
"<del>" "</del>")))
(Notice the commented out line.)
Make the change through Emacs' customization facility:
M-x customize RET
In the search box enter Org Emphasis and click Search.
Click the down arrow next to Org Emphasis Alist to reveal its value.
Find and click the second DEL button—corresponding to the italic list item.
Click the Save for future sessions button at the top of the buffer.
You can use
#+OPTIONS: *:nil
to turn off text-emphasis (bold,italics,underline). This will however only work on export itself, the emphasis will still be visible.
See the manual for other export options.
If you like the standard emphasis functionality of the forward slashes in org-mode, you could also just define a new environment. I put something like the following in the preamble whenever I do phonetics/phonology typesetting:
\newcommand\uRep[1]{$/$\textipa{#1}$/$}

Right-align text in Emacs

Sometimes, I have a text file like this in Emacs:
some text 123 17
other text 1 0
still more 12 8
last one 1234 123
I would like to right-align the numbers (using spaces), changing it into something like this:
some text 123 17
other text 1 0
still more 12 8
last one 1234 123
How can this be done in Emacs?
align-regexp can do this. Mark the region, and then use:
C-uM-x align-regexp RET \(\s-+[0-9]*\)[0-9] RET -1 RET 4 RET y
That should be the simplest approach.
(Edit: In fact, you don't even need to separate out that final digit; \(\s-+[0-9]+\) works just as well for the regexp.)
See the interactive prompts and C-hf align-regexp RET and the align-rules-list variable for what that is actually doing.
The noteworthy part is that by specifying a negative number for the group, align-regexp sets the justify attribute:
`justify'
It is possible with `regexp' and `group' to identify a
character group that contains more than just whitespace
characters. By default, any non-whitespace characters in
that group will also be deleted while aligning the
alignment character. However, if the `justify' attribute
is set to a non-nil value, only the initial whitespace
characters within that group will be deleted. This has
the effect of right-justifying the characters that remain,
and can be used for outdenting or just plain old right-
justification.
Alternatively the various table-editing options can also deal with this (e.g. org, ses, table-capture/release), or you could do it with an elisp replacement pattern.
e.g. The following should do more or less what you're looking for, provided that the file is already using spaces for alignment (you can use untabify to remove the tabs if not), and that all lines are the same length (i.e. trailing spaces are needed on some lines if the final column is of varying length).
C-M-% \([0-9]+\)\([[:space:]]+\) RET \,(format (concat "%" (number-to-string (1- (length \&))) "d ") (string-to-number \1)) RET

How can I use csquotes with LaTeX export in Org-mode?

When using csquotes quotation marks are added by csquotes according to context. This is done by marking up quotation with the \enquote macro, i.e. as \enquote{text}.
When exporting to LaTeX from Org-mode quotation marks are marked up as `` and '', e.g. as ``text''.
Can Org-mode export to LaTeX with quotations marked up by \enquote?
I found http://comments.gmane.org/gmane.emacs.orgmode/43689 where such a feature is being planned but I do not understand whether it was implemented.
On a related note there is integration of csquotes in AUCTeX. The integration is that when a document loads csquotes then " is expanded to \enquote{ and } respectively. This is not what I am asking for but there might be bits of code that can be interested in setting up Org-mode to export quotations marked up by \enquote.
Following that thread to the end and then looking at the changelog for the 7.7 (see Headline for version 7.7) release I find that they have added a variable org-latex-export-quotes. I'm not entirely sure how this would have to be customized, but I suspect it would have to end up something as follows:
Original (included since it only appears in 7.7 and I believe you're running 7.6):
(defcustom org-export-latex-quotes
'(("fr" ("\\(\\s-\\|[[(]\\)\"" . "«~") ("\\(\\S-\\)\"" . "~»") ("\\(\\s-\\|(\\)'" . "'"))
("en" ("\\(\\s-\\|[[(]\\)\"" . "``") ("\\(\\S-\\)\"" . "''") ("\\(\\s-\\|(\\)'" . "`")))
"Alist for quotes to use when converting english double-quotes.
The CAR of each item in this alist is the language code.
The CDR of each item in this alist is a list of three CONS:
- the first CONS defines the opening quote;
- the second CONS defines the closing quote;
- the last CONS defines single quotes.
For each item in a CONS, the first string is a regexp
for allowed characters before/after the quote, the second
string defines the replacement string for this quote."
To:
(setq org-export-latex-quotes
'(("en" ("\\(\\s-\\|[[(]\\)\"" . "\\enquote{") ("\\(\\S-\\)\"" . "}") ("\\(\\s-\\|(\\)'" . "`"))))
I just tested this and it does perform as expected. The sample file:
* test
this is a test of "this"
exports as (preamble omitted):
\section{test}
\label{sec-1}
this is a test of \enquote{this}
I do not know if it is possible to easily add this feature within 7.6, the easier solution would likely be to upgrade. Otherwise the easier solution in 7.6 would likely be to create a custom link (see: Org Tutorials). This would not be as fast but does provide the desired results within the features provided by 7.6.
#N.N. and others, the new org-mode export function in org 8.0 has a list named org-export-smart-quotes-alist. You can add the following to your init.el and it will turn regular " double quotes into enquote{}, and ' single quotes into enquote*{}.
(add-to-list 'org-export-smart-quotes-alist
'("am"
(primary-opening :utf-8 "“" :html "“" :latex "\\enquote{" :texinfo "``")
(primary-closing :utf-8 "”" :html "”" :latex "}" :texinfo "''")
(secondary-opening :utf-8 "‘" :html "‘" :latex "\\enquote*{" :texinfo "`")
(secondary-closing :utf-8 "’" :html "’" :latex "}" :texinfo "'")
(apostrophe :utf-8 "’" :html "’")))
A word of warning: if you want this to work in your org file's language, make sure you either have org-export-default-language set to "am" (or whatever you choose to use in the above form), or you put the appropriate #+LANGUAGE: am line at the top of your org file. If you don't, the org exporter won't call the above.

How to make part of a word bold in org-mode

How can I make org-mode markup work for a part of a word? For example, I'd like it to work for cases like this:
=Class=es
and this:
/Method/s
Based on my tests it seems like org-mode markup syntax works on complete words only.
These days, there is a way to do this (without using quoted HTML tags):
(setcar org-emphasis-regexp-components " \t('\"{[:alpha:]")
(setcar (nthcdr 1 org-emphasis-regexp-components) "[:alpha:]- \t.,:!?;'\")}\\")
(org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
Explanation
The manual says that org-emphasis-regexp-components can be used to
fine tune what characters are allowed before and after the markup characters [...].
It is a list containing five entries. The first entry lists characters that are allowed to immediately precede markup characters, and the second entry lists characters that are allowed to follow markup characters. By default, letters are not included in either one of these entries. So in order to successfully apply formatting to strings immediately preceded or followed by a letter, we have to add [:alpha:] (which matches any letter) to both entries.
This is what the calls to setcar do. The purpose of the third line is to rebuild the regular expression for emphasis based on the modified version of org-emphasis-regexp-components.
I don't think you can do it so that it shows up in the buffer as bold. If you just need it so that it appears bold when you export it to html, you can use:
th#<b>is is ha#</b>lf bold
See Quoting HTML tags
No, you can't do that. I searched for the same solution before and found nothing. A (very) bad hack is to do something like *Class* es (with a whitespace).
Perhaps you can write a short message to the creator, Carsten Dominik (Homepage), and ask him for a solution. He seems to be a nice guy.
A solution that has not been mentioned is to use a unicode zero width space (U+200B) in between the desired bolded and unbolded parts of a word.
To get the desired bolding of the word "Classes":
Type 'Class*es' in the buffer (without quotes).
Move the cursor between the '*' and 'e' characters.
Press C-x 8 RET (to execute the insert-char command).
Type 'zero width space' (without quotes) and press RET.
Move the cursor to the beginning of the word and insert a '*' character.
The word "Classes" should now have the desired appearance.
Note that there is the possibility that this will cause problems when exporting.
src_latex{\textbf{Class}es and \textit{Method}s}
Building up on the previous excellent answer
I had to modify it a bit in order to make it work with spacemacs. Indeed, from the spacamacs org-layer documentation, available here, we can read
Because of autoloading, calling to org functions will trigger the
loading up of the org shipped with emacs which will induce conflicts.
One way to avoid conflict is to wrap your org config code in a
with-eval-after-load block [...]
So, I put the following lines inside my dotspacemacs/user-config ()
(eval-after-load "org"
'(progn
(setcar org-emphasis-regexp-components " \t('\"{[:alpha:]")
(setcar (nthcdr 1 org-emphasis-regexp-components) "[:alpha:]- \t.,:!?;'\")}\\")
(org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
))

Which .emacs -file would you give for a Vim veteran?

I have used Vim for coding.
I want to learn Emacs too.
I would like to export at least some of the following customizations in my .vimrc to my .emacs.
My .vimrc
let Tlist_Auto_Open = 1
" http://stackoverflow.com/questions/165231/vim-dvorak-keybindings-rebinding
" Dvorak it!
no d h
no h j
no t k
no n l
no s :
no S :
no j d
no J D
no l n
no L N
" Added benefits
no - $
no _ ^
no N
no ; z
no T L
no P P
no p p
let Tex_ViewRuleComplete_pdf = '/usr/bin/open -a Skim $*.pdf'
set history=1000
set smartindent
set autoindent
set tabstop=4
set expandtab
set shiftwidth=3
set softtabstop=4
set number
set hlsearch
syntax on
set cursorline
highlight CursorLine guibg=#400000
set ruler
set textwidth=78
set foldcolumn=5
" REQUIRED. This makes vim invoke Latex-Suite when you open a tex file.
filetype plugin on
filetype indent on
" IMPORTANT: grep will sometimes skip displaying the file name if you
" search in a singe file. This will confuse Latex-Suite. Set your grep
" program to always generate a file-name.
set grepprg=grep\ -nH\ $*
" OPTIONAL: This enables automatic indentation as you type.
filetype indent on
" OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to
" 'plaintex' instead of 'tex', which results in vim-latex not being loaded.
" The following changes the default filetype back to 'tex':
let g:tex_flavor='latex'
" http://ubuntuforums.org/showthread.php?t=74889
set foldmethod=manual "folds by indentation, manual, indent
set nocompatible "Use Vim extensions
set backspace=indent,eol,start "More powerful backspacing
set nobackup "No backup file
set showmode "Tell when in insert mode
set showmatch "Show matching () {} etc
set hlsearch "Highlight what is searched for
set incsearch "Highlight as you type
if &t_Co > 2
syntax on
endif
set bg=dark
hi clear
if exists("syntax_on")
syntax reset
endif
"Allowable colors: red, yellow, green, blue, magenta,
" cyan, gray, black, gray
hi Normal ctermfg=gray ctermbg=none
hi ErrorMsg ctermfg=gray ctermbg=lightblue
hi Visual ctermfg=lightblue ctermbg=fg cterm=reverse
hi VisualNOS ctermfg=lightblue ctermbg=fg cterm=reverse,underline
hi Todo ctermfg=red ctermbg=darkblue
hi Search ctermfg=gray ctermbg=darkblue
hi IncSearch ctermfg=darkblue ctermbg=gray
hi SpecialKey ctermfg=darkcyan
hi Directory ctermfg=cyan
hi Title ctermfg=magenta cterm=bold
hi WarningMsg ctermfg=red
hi WildMenu ctermfg=yellow ctermbg=black cterm=none
hi ModeMsg ctermfg=lightblue
hi MoreMsg ctermfg=darkgreen ctermfg=darkgreen
hi Question ctermfg=green cterm=none
hi NonText ctermfg=darkblue
hi StatusLine ctermfg=blue ctermbg=gray cterm=none
hi StatusLineNC ctermfg=black ctermbg=gray cterm=none
hi VertSplit ctermfg=black ctermbg=gray cterm=none
"hi Folded ctermfg=darkgrey ctermbg=black cterm=bold
"hi FoldColumn ctermfg=darkgrey ctermbg=black cterm=bold
hi LineNr ctermfg=gray cterm=none
hi DiffAdd ctermbg=darkblue cterm=none
hi DiffChange ctermbg=magenta cterm=none
hi DiffDelete ctermfg=blue ctermbg=cyan
hi DiffText cterm=bold ctermbg=red
hi Cursor ctermbg=brown
hi lCursor ctermbg=darkgreen
hi Comment ctermfg=lightgreen cterm=none
hi Constant ctermfg=cyan cterm=none
hi Identifier ctermfg=gray cterm=none
hi Statement ctermfg=red cterm=none
hi PreProc ctermfg=yellow cterm=bold
hi Type ctermfg=darkyellow cterm=none
hi Special ctermfg=magenta cterm=none
hi Underlined cterm=underline
hi Ignore cterm=none
What is in your .emacs which would allow me to have some of the above features?
The EMACS Starter Kit is helpful too.
My God -- you really remap your keyboard to Dvorak in your .vim?
Okay, here are some of the others:
set smartindent
set autoindent
There automagically in programming modes. For text modes, look at 'autoindent-mode" and "filladapt."
set tabstop=4
set shiftwidth=3
set softtabstop=4
(setq c-basic-offset 4) ; indents 4 chars
(setq tab-width 4) ; and 4 char wide for TAB
(setq indent-tabs-mode nil) ; And force use of spaces
(There's no easy equivalent for shiftwidth; EMACS uses a smarter autindentation algorithm.
set expandtab
(setq indent-tabs-mode nil)
set number
There is a way to get numbered lines, but I never use it and don't remember it.
syntax on
(turn-on-font-lock)
set cursorline
There are a pile of cursor settings, look through M-x apropos cursor
Some of the other stuff is also available, these are the things I know of offhand.
Try these, and experiment.
dotfiles emacs
dotfiles.org
Apart from those, always a nice link:
GNU Emacs Manuals Online
You can get numbered lines with (linum-mode 1) or (global-linum-mode 1) for every buffer. This feature is currently only in the CVS Emacs. See further choices.
For opening PDF documents inside Emacs, there is doc-view-mode. See View PDF/PS/DVI files in an Emacs buffer for further instructions.
Anyway, it'd better if you start up learning Emacs with Emacs Starter Kit as Charlie Martin suggested, and then find yourself what you're really missing. Emacs world is different than Vi's. And you can always browse Stack Overflow to find if your question was already answered.
you definitely should try evil-mode. Best vim emulator for emacs:
http://www.emacswiki.org/emacs/Evil