When I run, M-x, <RET>, set-frame-title, I am able to change the title of an Emacs frame to whatever I want.
However, I am trying to do this programmatically from within the .emacs file. In particular, I have been trying to do something like this, but to no avail.
(setq frame-title-format '("new title here"))
How can I set the frame title from within the ELisp?
The doc for frame-title-format says:
It is used only on frames for which no explicit name has been set (see ‘modify-frame-parameters’).
There is no function set-frame-title in Emacs, but, if there were, it would have been probably using modify-frame-parameters ;-)
Here are a few copy and paste options with links to the actual string substitutions .
Option 1: is better for buffers like scratch that are temporary and don't exist on the filesystem.
Option 2: gives the absolute path to the file plus the major mode.
Option 3: is the most direct and contains both the string literal plus the buffer name by %-Construct.
(setq frame-title-format
(concat "%b - emacs#" (system-name)))
(setq-default frame-title-format '("%f [%m]"))
(setq frame-title-format "New title here - %b " )
Option 2 was pulled from here: emacs-stackexchange answer
String substitutions are know as %-Constructs , you have a lot of choices for what variables you'd like in the title. You can also find more information using the links #sds provided.
Related
When I am using Emacs to edit a ".s" file, I want to change the comment from ";;" to "//". I can't seem to find out how to change the comment identifiers?
For example, when I comment-region.
More information:
I appear to be in ASM-MODE which is the default mode for editing assembler files. I made sure that I was in asm-mode by
(setq auto-mode-alist
(append '(("\\.s$" . asm-mode)auto-mode-alist))
Because assembly programs typically use ; as the comment indicator, asm-mode uses this. However, for some reason I cannot figure the GNU assembler (GNU Binutils for Raspbian) 2.35.2 uses // or # or # for comments NOT a ;
Therefore, I would like to change the behaviour such that when I select a region and M-X comment-region it uses either // or # for comments. I cannot use the default comment character, I need to change it to either double-slashes // or an at symbol #
The question is really how do I go about changing the default comment character for in a mode?
Assuming that the major mode of the .s file is asm-mode, you can use the mode hook to tweak the comment start string:
(defun my/asm-comment-tweak ()
(setq-local comment-start "// "))
(eval-after-load "asm"
(add-hook 'asm-mode-hook #'my/asm-comment-tweak))
Adding the above to your init file should let you open a .s file, which will be in asm-mode. The last thing that is done by asm-mode is to run the mode hook which will call the function my/asm-comment-tweak: the function will set the buffer-local variable comment-start to the string you specified.
This pattern is very common: many problems in customizing emacs are solved in exactly the same way. You define a function that tweaks a variable and you arrange for the function to be called by the appropriate mode hook.
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 want the following behavior:
Append the word under cursor into a file(~/vocabulary.txt, for example)
Better still to bind a key for it.
Could anyone show me how to do it?
Should I put those code into .emacs ?
Try the following function:
(defun my-write-to-file ()
"Save word at point to file"
(interactive)
(write-region (concat (thing-at-point 'word) "\n") nil "~/vocabulary.txt" 'append))
When called, this function will save the word at point (the word the cursor is on or the word right before the cursor) to ~/vocabulary.txt.
You can bind it to a key (C-c w in this case, but you can change it to whatever you like) like this:
(global-set-key (kbd "C-c w") 'my-write-to-file)
To use, simply put the function and the keybinding assignment in your .emacs.
#Elethan wrote you a command that does just what you ask for, and bound it to a key.
It might also help to mention some general commands that you can use for this kind of thing. M-x append-to-file appends the region contents to a file, and M-x write-region prepends.
The manual is your friend for things like this. See nodes Misc File Ops and Accumulating Text.
Be aware too that for the two commands just mentioned, as the manual says about append-to-file (it should say it about both):
You should use append-to-file only with files that are not being
visited in Emacs. Using it on a file that you are editing in Emacs
would change the file behind Emacs’s back, which can lead to losing some
of your editing.
Accumulating Text also tells you about commands for adding text to a buffer, including the case of adding to a buffer for a file that you are visiting (as opposed to what the above quote warns you about for append-to-file). These include commands append-to-buffer and prepend-to-buffer.
I'm learning to use emacs and org-mode. I create a few tags, in a .org file, as such :outline: lets say.
And then searched for them using:
C-c a m outline
C-c a t outline
C-c \ outline
And the output is always (basically, did't find anything):
Headlines with TAGS match: outline
Press `C-u r' to search again with new search string
What am I doing wrong. Can someone please tell me what I'm missing?
Thanks in advance.
Common problems when initially setting up org-mode include, but are not limited to, properly configuring the org-agenda-files variable. A user may choose to have one or more files, or a directory.
Here is an example of multiple files:
(setq org-agenda-files
(list "~/org/gtd.org" "~/org/work.org" "~/org/personal.org"))
Here is an example of a directory:
(setq org-agenda-files (list "~/"))
(setq org-agenda-file-regexp "\\`[^.].*\\.org\\|.todo\\'")
It is interesting to note that there is also non-interactive function with the same name, which looks up the configuration of the org-agenda-files variable -- the function is what org-mode generally relies upon when any other function looks up the value of the variable. To see an example of how that non-interactive function works, the user can do something like this:
M-x eval-expression RET (org-agenda-files) RET
The importance of setting the org-agenda-files variable can be seen by examining the function org-match-sparse-tree, which in turn calls org-scan-tags using org-make-tags-matcher, which uses org-global-tags-completion-table, which uses the function org-agenda-files, which uses the variable org-agenda-files. If the variable org-agenda-files is not set up correctly, a tags search and auto-completion of tags will not work correctly.
Another common issue arises when the variable org-tag-alist has not yet been properly set up -- here is a link to the manual page on that issue: http://www.orgmode.org/manual/Setting-tags.html
BACKGROUND: In org-mode, the variable org-archive-location is set to "%s_archive::" by default, so that a file "toto.org" archives into a file "toto.org_archive". I would like it to archive to "toto.ref" instead. I am using org-mode version 7.4 (out of the git server).
I would have thought it to be as simple as
(setq org-archive-location
`(replace-regexp-in-string ".org" ".ref" %s)
)
But I was pointed out that this was not proper in LISP (plus, it did not work). My final solution is as follow, you should be able to adapt to most clever configurations of org-archive-location:
(setq org-archive-location "%s::* ARCHIVES")
(defadvice org-extract-archive-file (after org-to-ref activate)
(setq ad-return-value
(replace-regexp-in-string "\\.org" ".ref" ad-return-value)
)
)
Note that:
1) I voluntarily did not add a $ at the end of ".org" so that it would properly alter "test.org.gpg" into "test.ref.gpg".
2) It seems that one should use the regular expression "\.org" (rather than, say, ".org") (longer explanation below in the answers).
You can't define a variable in Emacs such that its value is obtained by running code; variables have simple, static values.
You can achieve the effect you described by advising the function org-extract-archive-file, which is the one that generates an archive location from org-archive-location:
(defadvice org-extract-archive-file (after org-to-ref activate)
(setq ad-return-value
(replace-regexp-in-string "\\.org" ".ref" ad-return-value)))
This works for me now, but of course the internals of org-mode are subject to change and this solution may not work forever.
You should not quote an expression that you want to evaluate. Note also that in a regular expression, . matches any character.
Here is an example of how to set the file, the location (e.g., main heading) in the file, and whether or not to include additional archive information:
(let* (
(org-archive-location "~/todo.org::* TASKS")
(org-archive-save-context-info nil))
...)
You can try this: #+ARCHIVE: %s.ref:: at the beginning of your org file.
Read more about it here.
Also, other interesting option is to set inside your headtree the following, for instance:
* Main Header of tree
:PROPERTIES:
:ARCHIVE: toto.ref:: * Main Header of tree in archive file
:END:
** sub tree of main header and so on
The latter I took from this video.