Is it possible in Common Lisp to get a symbol-name without the uppercase result?
(symbol-name 'aAbB)
;; => "AABB"
(OTHER_FUNCTION? 'aAbB)
;; => "aAbB"
I would like to use a symbol name as a string but case-sensitive.
Your symbol is actually all uppercase, because the reader already upcases it. In order to prevent that, you can either use a different readtable-case or escape the symbol, using either enclosing pipe symbols: '|aAbB| or a backslash for the next character: '\aA\bB.
There is quite a full answer on this question: Why is Common Lisp case insensitive
"The readtable objects has an attribute, readtable-case, that controls how the reader interns and evaluates the symbols read. you can setf readtable-case to :upcase(default), :downcase, :preserve, :invert.
By default, the readtable-case is set to :upcase, which causes all symbols to be converted to upcase."
I understand that both suppress evaluation of a symbol or expression. But the backtick is used for macro definitions while the apostrophe is used for symbols (among other things). What is the difference, semantically speaking, between these two notations?
Backticks allow for ,foo and ,#foo to interpolate dynamic parts into the quoted expression.
' straight up quotes everything literally.
If there are no comma parts in the expression, ` and ' can be used interchangeably.
A standard quote is a true constant literal and similar lists and list that end with the same structure can share values:
'(a b c d) ; ==> (a b c d)
A backquoted structure might not be a literal. It is evaluated as every unquote needs to be evaluated and inserted into place. This means that something like `(a ,#b ,c d) actually gets expanded to something similar to (cons 'a (append b (cons c '(d)))).
The standard is very flexible on how the implementations solves this so if you try to macroexpand the expression you get many different solutions and sometimes internal functions. The result though is well explained in the standard.
NB: Even though two separate evaluation produces different values the implementation is still free to share structure and thus in my example '(d) has the potential to be shared and if one would use mutating concatenation of the result might end up with an infinite structure.
A parallel to this is that in some algol languages you have two types of strings. One that interpolates variables and one that don't. Eg. in PHP
"Hello $var"; // ==> 'Hello Shoblade'
'Hello $var'; // ==> 'Hello $var'
I'm trying to check if the return value of (read-event) is a graphical character. Example: a (97) is a graphical character. return is not a graphical character. f1 is not a graphical character and so on. I tried a lot of ways to do that, but nothing works.
Did you try char-displayable-p? C-h f tells you:
char-displayable-p is an autoloaded Lisp function in mule-util.el.
(char-displayable-p CHAR)
Return non-nil if we should be able to display CHAR.
On a multi-font display, the test is only whether there is an
appropriate font from the selected frame's fontset to display
CHAR's charset in general. Since fonts may be specified on a
per-character basis, this may not be accurate.
But that says that it expects CHAR to be a character. So you might want to also test to make sure that it is, using characterp.
(In fact, characterp might be all you need: (characterp (read-event)). It depends on whether you care if a given character is displayable in your environment, i.e., given the fonts you have.)
You can often find a function with a name like char-displayable-p using apropos. Try, for instance:
M-x apropos RET char display RET
That shows you something like this:
Type RET on a type label to view its full documentation.
char-displayable-p
Function: Return non-nil if we should be able to display CHAR.
Properties: autoload
glyphless-char-display
Variable: Char-table defining glyphless characters.
Properties: char-table-extra-slots variable-documentation
glyphless-char-display-control
User option: List of directives to control display of glyphless characters.
Properties: standard-value custom-version custom-type custom-options custom-set custom-requests variable-documentation
nobreak-char-display
Variable: Control highlighting of non-ASCII space and hyphen chars.
Properties: variable-documentation
tabulated-list-glyphless-char-display
Variable: The glyphless-char-display table in Tabulated List buffers.
Properties: variable-documentation
update-glyphless-char-display
Function: Make the setting of glyphless-char-display-control take effect.
In org mode, if I want to format text a monospace verbatim, i.e. ~...~, if it is inside quotes: ~"..."~, it is not formatted (left as is).
Also, are quotes a reserved symbol, if so, what do they mean? (they don't seem to affect the generated HTML / inside Emacs display).
The culprit in this case is the regular expression in org-emph-re org-verbatim-re, responsible for determining if a sequence of characters in the document is to be set verbatim or not.
org-verbatim-re is a variable defined in `org.el'.
Its value is
"\([ ('\"{]\|^\)\(\([=~]\)\([^
\n,\"']\|[^
\n,\"'].?\(?:\n.?\)\{0,1\}[^
\n,\"']\)\3\)\([- .,:!?;'\")}\]\|$\)"
quotes and double quotes are explicitly forbidden inside verbatim characters =~ by
[^
\n,\"']\|[^
\n,\"']
I found discussions dating back 3 years comming to the conclusion that you have to tinker with this regular expression and set the variable org-emph-re/org-verbatim-re to something that matches your wishes in your emacs setup (maybe a file local variable works as well). You can experiment by excluding double quotes from the excluding character classes and outside matches as in
"\([ ('{]\|^\)\(\([*/_=~+]\)\([^
\n,']\|[^
\n,'].?\(?:\n.?\)\{0,1\}[^
\n,']\)\3\)\([- .,:!?;')}\]\|$\)"
but looking at that regex, heaven knows what happens to complex documents -- you have to try...
Edit: as it happens, if I evalute the following as region, quotes inside = are exported correctly, but nothing else is :-), I investigate further when I have more time.
(setq org-emph-re "\([ ('{]\|^\)\(\([*/_=~+]\)\([^
\n,']\|[^
\n,'].?\(?:\n.?\)\{0,1\}[^
\n,']\)\3\)\([- .,:!?;')}]\|$\)")
Edit 2:: Got it to work by changing org.el directly:
Change the line following (defvar org-emphasis-regexp-components from '(" \t('\"{" "- \t.,:!?;'\")}\\" " \t\r\n,\"'" "." 1) to '(" \t('{" "- \t.,:!?;')}\\" " \t\r\n,'" "." 1) and recompile org then restart emacs.
This was a defcustom prior to the 8.0 release, it isn't anymore, so you have to live with this manual modification.
regards,
Tom
Finally, I found a solution from http://comments.gmane.org/gmane.emacs.orgmode/82571
According to that thread, the regexp for verbatim is built from variable org-emphasis-regexp-components, which defines legal characters before, after, at the border of, or in the body of emphasis; and verbatim is one of the emphasis environment in org mode.
A workable setting given by that thread:
(setcar (nthcdr 2 org-emphasis-regexp-components) " \t\n,")
(custom-set-variables `(org-emphasis-alist ',org-emphasis-alist))
For small amounts of characters which have some unwanted effect in Emacs org-mode (because being metacharacters) it may be helpful to have a look at special symbols in org-mode (org-entities.el).
So for example " can be encoded by \quot{} (where the braces pair at the end is not mandatory, but needed if no whitespace follows).
So instead ="..."= you would write =\quot{}...\quot{}=.
That is some typing more and looks pretty ugly. But for the latter org-mode has a solution: by C-c C-x \ you can toggle a display magic for those symbols. If the magic is active, so directly after typing \quot{} resp. \quot{} a " will be displayed.
Besides, this symbols list can easily be extended, f.e.
(add-to-list 'org-entities
'("backslash" "\\textbackslash" nil "\\" "\\" "\\" "\\"))
Nevertheless I am heavily missing easier escaping in org-mode, besides the above solution and besides escaping a whole line by a : at its beginning.
I'd be happy if =verbatim= in all cases would leave the text between the ='s unchanged. Not =this*bold*text=, but =this *bold* text=. Like we know that from each well-designed markup/-down language.
But, of course, this is better placed at the org-mode development pages. Ideally with a fitting patch... :-)
I've met similar problem, and thanks #chaiko for a basic solution. However, #chaiko's solution only work for org-mode's fontification, it doesn't affect org-export. To get correct exported document, you need to do some more extra hack to org-mode's parser by (org-element--set-regexps).
So the full code snippets should be something like:
(setcar (nthcdr 2 org-emphasis-regexp-components) " \t\n\r")
(custom-set-variables `(org-emphasis-alist ',org-emphasis-alist))
(org-element--set-regexps)
I've integrated this to my oh-my-emacs project: https://github.com/xiaohanyu/oh-my-emacs/blob/e82fce10d47f7256df6d39e32ca288d0ec97a764/core/ome-org.org#code-block-fontification .
I'm working on a system that uses M4 to expand some files out, but I'm getting a problem with the expansion in certain cases. The convention for definition / macro naming (which I'd rather not change if possible) is __<name>__ (i.e. double leading and trailing underscores.) So this expands correctly:
define(`__ROOT__', `/home/mydir')
...
__ROOT__/bin
gives
/home/mydir/bin
but,
define(`__PREFIX__', `App_Mnemonic')
...
__PREFIX___some_service
should give:
App_Mnemonic_some_service
but gives
__PREFIX___some_service
(i.e. it missed the expansion)
I presume the lack of space between the trailing underscore of the macro and the valid underscore of the underlying text is confusing m4. Is there anything I can do about this? Can I delimit the macro with silent braces, for example, like enviromnment variables?
Deceptively simple really, all I had to do in the underlying text was change this:
__PREFIX___some_service
for this:
__PREFIX__()_some_service
It looks a bit clunky perhaps, but it is a macro after all and there's no need to change the macro definition. So this can stay as it is:
define(`__PREFIX__', `App_Mnemonic')