How to ignore a local variables list in text? - emacs

I'm writing the readme (in org-mode) for a new emacs mode, and in the installation instructions we have how to enable the mode on a per-file basis:
or at the end of your file:
#+BEGIN_SRC emacs-lisp
! Local Variables:
! mode: f90-namelist
! End:
#+END_SRC
The problem is that this puts the README.org file into our new f90-namelist-mode and not org-mode. Putting another local variables list at the end of the file with # mode: org doesn't work, although putting
# -*- enable-local-variables: query -*-
lets me accept or reject all of the local variables, and emacs then determines the major mode from the .org file extension. This then precludes having any other local variables I might like to include.
Is there a more elegant way to include a literal local variables list in the text?

Quoting from the Emacs manual:
The start of the local variables list should be no more than 3000
characters from the end of the file, and must be on the last page if
the file is divided into pages.
So to make sure your in text local variables will be ignored, add a page break (C-q C-l) before the real list of local variables or at the end of the file if you don't have local variables:
or at the end of your file:
#+BEGIN_SRC emacs-lisp
! Local Variables:
! mode: f90-namelist
! End:
#+END_SRC
^L
This will work for all local variables, not only the major mode.
If you don't want to export the page break, just comment it, as suggested by #lunaryorn.

Here's how iostream header looks like:
// Standard iostream objects -*- C++ -*-
...
This is the standard way to specify the mode not only in Emacs,
but on the whole of Linux, for all editors, which choose to parse it.
I recommend you to go this way.
Also, enabling local variables is a faux pas from my viewpoint,
as it can lead to a mess that Microsoft Word had with VBA: viruses everywhere.
Source code or documents should not execute themselves.

Related

what does means #+keyword: means in org buffer

in emacs org mode, I saw #+ prefix many times. I think this is like option but I don't know what it is. I have tried to know them, I have been googling, but I couldn't find any good document. anybody know these symbol? is this org macros?
It is just plain text that you write in an org mode file. It may have two different functions:
1.- If you write it at the beginning of the file, it serves as a metadata descriptor or to include options for the file [1]. For example:
#+TITLE: This is the title of this file
#+AUTHOR: Loretta
#+DATE: 2022-10-15
#+STARTUP: content <--- option for displaying the contents
#+OPTIONS: H:3 toc:nil \n:nil #:t ::t |:t <--- different export options
2.- To create a block inside the file. This block may be code meant to be executed [2], a quotation, a comment, etc:
#+begin_src emacs-lisp
(+ 1 2 3 4 5 6 7)
#+end_src
#+begin_comment
Check the following paragraph. I am not really sure if it
has taken into account all the variables.
#+end_comment
[1] See https://orgmode.org/manual/In_002dbuffer-Settings.html for buffer settings and https://orgmode.org/manual/Export-Settings.html for export settings.
[2] See https://orgmode.org/manual/Literal-Examples.html for code blocks.

org mode export to markdown and character entity problems

I need to export a lot of documents written with Emacs-Orgto markdown. I am using the export via-pandoc. Everything works fine except for the multitude of special symbols written using org-syntax. Just an example the β character which in org is written \beta in the exported document I have \\beta instead of β . Is there a way to fix this instead of manually change few hundreds of symbols ?
To replace text in a single file, you simply type M-x replace-string. To replace strings for multiple files, follow the following instructions:
Assemble a list of files you want to operate on with either find-dired, find-name-dired or find-grep-dired.
Mark all files in the resulting Dired buffer using t.
Use Q to start a query-replace-regexp session on the marked files.
To accept all replacements in each file, hit !.
I don't use pandoc but with a similar problem exporting org-mode files to html I found I needed to enter the entities as '\beta{}' and not just as '\beta' (without the quotes)

Emacs: How to associate different initialization configurations with different file formats?

What's the best way to associate file extensions with my own customizations? For example, when I open a .py file the frame would be bigger and split into 2 windows, but when a .tex file is opened the frame would be smaller with just one window. Should I split my .emacs and write all configurations associated with python in a .el file (key bindings, python shell = ipython, etc ...) and for latex in another .el file (load auctex, pdf mode = default, etc ...)? How would I "call" the files and make them work appropriately (if that'a possible and good solution)?
(First, +1 to #phils's comment. You will get better help if you are more specific about what you need/want.)
Depending on just what you need/want, see also variable (not option) file-name-handler-alist. You might not need it, but you might.
You can make use of it if you intend all or particular operations on the files to involve additional actions (such as those you describe). For any operations where you do not need special treatment, just provide the default behavior. For the others, provide the default behavior plus the extra behavior (in whichever order is appropriate).
See (elisp) Magic File Names for more information.

What does this "a file local variable" mean?

I am reading about the kill-emacs-hook variable in the emacs manual.
It says:
kill-emacs-hook is a variable defined in `C source code'.
Its value is
(org-babel-remove-temporary-directory migemo-pattern-alist-save)
This variable is potentially risky when used as a file local variable.
Documentation:
Hook to be run when `kill-emacs' is called.
...abbr...
I do not understand this sentence: "a file local variable". What does this "a file local variable" mean?
Emacs has a facility for specifying buffer variables in a file's contents. http://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html#Specifying-File-Variables
This is frequently used to specify the file's mode -*- python -*- or e.g. the preferred indentation style or tab width; but it potentially can give the file's author complete control over your Emacs, if you allow it. However, for variables deemed to be unsafe, the default behavior is to ask the user for confirmation before permitting the settings to take effect. See the manual for further discussion.
By defaul, when you set a variable with setq the value is global. It means that all the buffers will see the new value.
However, certain variables, called buffer local variables, work differently. When a buffer local variable is set, its value changes only for the buffer where the setq happened. The other buffers do not see the change.
These buffer local variables can take their value from the content of the file currently visited by the buffer. If the file contains a properly formatted string (see #tripleee's answer) then a buffer local variable will be initialized with the value when the file is open.
As a side note, directory local variables also exist which set a buffer local variable for every buffer visiting a file in the directory.

Setting relative Tex-Master file in Latex

I use Aquamacs and TeX Live 2009 to edit my LaTeX files. As my publications tend to get quite big, I want to structure the source folder containing all my LaTeX files. Like e.g.
[bib]
[images]
[chapters]
chapter1.tex
chapter2.tex
main.tex
One can define the %%% TeX-master: "main" local variable at the end of each "sub" file to define a master file that contains all headers etc. That works fine if the subfiles are in the same directory as the main file. If I try to define the main file here (e.g. main.tex in chapter1.tex), LaTeX cannot find the specified file.
What can I do in this case?
In Aquamacs' menu bar go to Latex / Multifile/Parsing / Reset Buffer or Shortcut ^C ^N.
When specifying %%% TeX-master: "../main" in one of the chapters in the subfolders, the main tex file is correctly compiled!
Just an idea (not tested):
%%% TeX-master: "../main"
.. is the usual Unix shortcut for one directory level above. I don't know if this works for the TeX-master variable of AUCTeX, but it is worth a try.
The main latex file which contains all the headers and gets compile can include all the chapter files via:
[...]
\input{chapters/chapter1.tex}
\input{chapters/chapter2.tex}
\input{chapters/chapterTitleOfChapter.tex}
[...]
You do not need to have each chapter include the main file. Or am I missing something you are doing?