]> git.lyx.org Git - lyx.git/blob - src/Buffer.h
Cmake build: Don't use temporary doc-files as source for installation
[lyx.git] / src / Buffer.h
1 // -*- C++ -*-
2 /**
3  * \file Buffer.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef BUFFER_H
13 #define BUFFER_H
14
15 #include "OutputEnums.h"
16
17 #include "support/unique_ptr.h"
18 #include "support/strfwd.h"
19 #include "support/types.h"
20
21 #include <map>
22 #include <list>
23 #include <set>
24 #include <string>
25 #include <vector>
26
27
28 namespace lyx {
29
30 class BiblioInfo;
31 class BibTeXInfo;
32 class BufferParams;
33 class DispatchResult;
34 class DocIterator;
35 class docstring_list;
36 class ErrorList;
37 class FuncRequest;
38 class FuncStatus;
39 class Inset;
40 class InsetLabel;
41 class InsetRef;
42 class Font;
43 class Format;
44 class Lexer;
45 class Text;
46 class LyXVC;
47 class LaTeXFeatures;
48 class Language;
49 class MacroData;
50 class MacroNameSet;
51 class MacroSet;
52 class OutputParams;
53 class otexstream;
54 class Paragraph;
55 class ParConstIterator;
56 class ParIterator;
57 class ParagraphList;
58 class TeXErrors;
59 class TexRow;
60 class TocBackend;
61 class Undo;
62 class WordLangTuple;
63
64 namespace frontend {
65 class GuiBufferDelegate;
66 class WorkAreaManager;
67 } // namespace frontend
68
69 namespace support {
70 class DocFileName;
71 class FileName;
72 class FileNamePairList;
73 } // namespace support
74
75 namespace graphics {
76 class PreviewLoader;
77 class Cache;
78 } // namespace graphics
79
80
81 class Buffer;
82 typedef std::list<Buffer *> ListOfBuffers;
83 /// a list of Buffers we cloned
84 typedef std::set<Buffer *> CloneList;
85
86
87 /** The buffer object.
88  * This is the buffer object. It contains all the information about
89  * a document loaded into LyX.
90  * The buffer object owns the Text (wrapped in an InsetText), which
91  * contains the individual paragraphs of the document.
92  *
93  *
94  * I am not sure if the class is complete or
95  * minimal, probably not.
96  * \author Lars Gullik Bjønnes
97  */
98
99 class MarkAsExporting;
100
101 class Buffer {
102 public:
103         /// What type of log will \c getLogName() return?
104         enum LogType {
105                 latexlog, ///< LaTeX log
106                 buildlog  ///< Literate build log
107         };
108
109         /// Result of \c readFile()
110         enum ReadStatus {
111                 ReadSuccess,
112                 ReadCancel,
113                 // failures
114                 ReadFailure,
115                 ReadWrongVersion,
116                 ReadFileNotFound,
117                 ReadVCError,
118                 ReadAutosaveFailure,
119                 ReadEmergencyFailure,
120                 ReadNoLyXFormat,
121                 ReadDocumentFailure,
122                 // lyx2lyx
123                 LyX2LyXNoTempFile,
124                 LyX2LyXNotFound,
125                 LyX2LyXOlderFormat,
126                 LyX2LyXNewerFormat,
127                 // other
128                 ReadOriginal
129         };
130
131         enum ExportStatus {
132                 // export
133                 ExportSuccess,
134                 ExportCancel,
135                 ExportError,
136                 ExportNoPathToFormat,
137                 ExportTexPathHasSpaces,
138                 ExportConverterError,
139                 // preview
140                 // Implies ExportSuccess.
141                 PreviewSuccess,
142                 // The exported file exists but there was an error when opening
143                 // it in a viewer.
144                 PreviewError
145         };
146
147         ///
148         enum UpdateScope {
149                 UpdateMaster,
150                 UpdateChildOnly
151         };
152
153         /// Constructor
154         explicit Buffer(std::string const & file, bool readonly = false,
155                 Buffer const * cloned_buffer = 0);
156
157         /// Destructor
158         ~Buffer();
159
160         /// Clones the entire structure of which this Buffer is part, starting
161         /// with the master and cloning all the children, too.
162         Buffer * cloneFromMaster() const;
163         /// Just clones this single Buffer. For autosave.
164         Buffer * cloneBufferOnly() const;
165         ///
166         bool isClone() const;
167
168         /** High-level interface to buffer functionality.
169             This function parses a command string and executes it.
170         */
171         void dispatch(std::string const & command, DispatchResult & result);
172
173         /// Maybe we know the function already by number...
174         void dispatch(FuncRequest const & func, DispatchResult & result);
175
176         /// Can this function be exectued?
177         /// \return true if we made a decision
178         bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
179
180         ///
181         DocIterator getParFromID(int id) const;
182         /// do we have a paragraph with this id?
183         bool hasParWithID(int id) const;
184
185         ///
186         frontend::WorkAreaManager & workAreaManager() const;
187
188         /** Save file.
189             Takes care of auto-save files and backup file if requested.
190             Returns \c true if the save is successful, \c false otherwise.
191         */
192         bool save() const;
193         /// Renames and saves the buffer
194         bool saveAs(support::FileName const & fn);
195
196         /// Write document to stream. Returns \c false if unsuccessful.
197         bool write(std::ostream &) const;
198         /// Write file. Returns \c false if unsuccessful.
199         bool writeFile(support::FileName const &) const;
200
201         /// \name Functions involved in reading files/strings.
202         //@{
203         /// Loads the LyX file into the buffer. This function
204         /// tries to extract the file from version control if it
205         /// cannot be found. If it can be found, it will try to
206         /// read an emergency save file or an autosave file.
207         /// \sa loadThisLyXFile
208         ReadStatus loadLyXFile();
209         /// Loads the LyX file \c fn into the buffer. If you want
210         /// to check for files in a version control container,
211         /// emergency or autosave files, one should use \c loadLyXFile.
212         /// /sa loadLyXFile
213         ReadStatus loadThisLyXFile(support::FileName const & fn);
214         /// import a new document from a string
215         bool importString(std::string const &, docstring const &, ErrorList &);
216         /// import a new file
217         bool importFile(std::string const &, support::FileName const &, ErrorList &);
218         /// read a new document from a string
219         bool readString(std::string const &);
220         /// Reloads the LyX file
221         ReadStatus reload();
222 //FIXME: The following function should be private
223 //private:
224         /// read the header, returns number of unknown tokens
225         int readHeader(Lexer & lex);
226
227         double fontScalingFactor() const;
228
229 private:
230         ///
231         typedef std::map<Buffer const *, Buffer *> BufferMap;
232         ///
233         void cloneWithChildren(BufferMap &, CloneList *) const;
234         /// save checksum of the given file.
235         void saveCheckSum() const;
236         /// read a new file
237         ReadStatus readFile(support::FileName const & fn);
238         /// Reads a file without header.
239         /// \param par if != 0 insert the file.
240         /// \return \c true if file is not completely read.
241         bool readDocument(Lexer &);
242         /// Try to extract the file from a version control container
243         /// before reading if the file cannot be found.
244         /// \sa LyXVC::file_not_found_hook
245         ReadStatus extractFromVC();
246         /// Reads the first tag of a LyX File and
247         /// returns the file format number.
248         ReadStatus parseLyXFormat(Lexer & lex, support::FileName const & fn,
249                 int & file_format) const;
250         /// Convert the LyX file to the LYX_FORMAT using
251         /// the lyx2lyx script and returns the filename
252         /// of the temporary file to be read
253         ReadStatus convertLyXFormat(support::FileName const & fn,
254                 support::FileName & tmpfile, int from_format);
255         /// get appropriate name for backing up files from older versions
256         support::FileName getBackupName() const;
257         //@}
258
259 public:
260         /// \name Functions involved in autosave and emergency files.
261         //@{
262         /// Save an autosave file to #filename.lyx#
263         bool autoSave() const;
264         /// save emergency file
265         /// \return a status message towards the user.
266         docstring emergencyWrite();
267
268 //FIXME:The following function should be private
269 //private:
270         ///
271         void removeAutosaveFile() const;
272
273 private:
274         /// Try to load an autosave file associated to \c fn.
275         ReadStatus loadAutosave();
276         /// Try to load an emergency file associated to \c fn.
277         ReadStatus loadEmergency();
278         /// Get the filename of the emergency file associated with the Buffer
279         support::FileName getEmergencyFileName() const;
280         /// Get the filename of the autosave file associated with the Buffer
281         support::FileName getAutosaveFileName() const;
282         ///
283         void moveAutosaveFile(support::FileName const & old) const;
284         //@}
285
286 public:
287         /// Fill in the ErrorList with the TeXErrors
288         void bufferErrors(TeXErrors const &, ErrorList &) const;
289
290         enum OutputWhat {
291                 FullSource,
292                 OnlyBody,
293                 IncludedFile,
294                 OnlyPreamble,
295                 CurrentParagraph
296         };
297
298         /// Just a wrapper for writeLaTeXSource, first creating the ofstream.
299         bool makeLaTeXFile(support::FileName const & filename,
300                            std::string const & original_path,
301                            OutputParams const &,
302                            OutputWhat output = FullSource) const;
303         /** Export the buffer to LaTeX.
304             If \p os is a file stream, and params().inputenc is "auto" or
305             "default", and the buffer contains text in different languages
306             with more than one encoding, then this method will change the
307             encoding associated to \p os. Therefore you must not call this
308             method with a string stream if the output is supposed to go to a
309             file. \code
310             ofdocstream ofs;
311             otexstream os(ofs);
312             ofs.open("test.tex");
313             writeLaTeXSource(os, ...);
314             ofs.close();
315             \endcode is NOT equivalent to \code
316             odocstringstream oss;
317             otexstream os(oss);
318             writeLaTeXSource(os, ...);
319             ofdocstream ofs;
320             ofs.open("test.tex");
321             ofs << oss.str();
322             ofs.close();
323             \endcode
324          */
325         void writeLaTeXSource(otexstream & os,
326                            std::string const & original_path,
327                            OutputParams const &,
328                            OutputWhat output = FullSource) const;
329         ///
330         void makeDocBookFile(support::FileName const & filename,
331                              OutputParams const & runparams_in,
332                              OutputWhat output = FullSource) const;
333         ///
334         void writeDocBookSource(odocstream & os, std::string const & filename,
335                              OutputParams const & runparams_in,
336                              OutputWhat output = FullSource) const;
337         ///
338         void makeLyXHTMLFile(support::FileName const & filename,
339                              OutputParams const & runparams_in) const;
340         ///
341         void writeLyXHTMLSource(odocstream & os,
342                              OutputParams const & runparams_in,
343                              OutputWhat output = FullSource) const;
344         /// returns the main language for the buffer (document)
345         Language const * language() const;
346         /// get l10n translated to the buffers language
347         docstring const B_(std::string const & l10n) const;
348
349         ///
350         int runChktex();
351         /// return true if the main lyx file does not need saving
352         bool isClean() const;
353         ///
354         bool isDepClean(std::string const & name) const;
355
356         /// Whether or not disk file has been externally modified. Uses a checksum
357         /// which is accurate but slow, which can be a problem when it is frequently
358         /// used, or used for a large file on a slow (network) file system.
359         bool isChecksumModified() const;
360
361         /// Flag set by the FileSystemWatcher.
362         /// Fast but (not so) inaccurate, can be cleared by the user.
363         bool notifiesExternalModification() const;
364         void clearExternalModification() const;
365
366         /// mark the main lyx file as not needing saving
367         void markClean() const;
368
369         ///
370         void markDepClean(std::string const & name);
371
372         ///
373         void setUnnamed(bool flag = true);
374
375         /// Whether or not a filename has been assigned to this buffer
376         bool isUnnamed() const;
377
378         /// Whether or not this buffer is internal.
379         ///
380         /// An internal buffer does not contain a real document, but some auxiliary text segment.
381         /// It is not associated with a filename, it is never saved, thus it does not need to be
382         /// automatically saved, nor it needs to trigger any "do you want to save ?" question.
383         bool isInternal() const;
384
385         void setInternal(bool flag);
386
387         /// Mark this buffer as dirty.
388         void markDirty();
389
390         /// Returns the buffer's filename. It is always an absolute path.
391         support::FileName fileName() const;
392
393         /// Returns the buffer's filename. It is always an absolute path.
394         std::string absFileName() const;
395
396         /// Returns the path where the buffer lives.
397         /// It is always an absolute path.
398         std::string filePath() const;
399
400         /** Contructs a file name of a referenced file (child doc, included graphics etc).
401          *  Absolute names are returned as is. If the name is relative, it is
402          *  interpreted relative to filePath() if the file exists, otherwise
403          *  relative to the original path where the document was last saved.
404          *  The original path may be different from filePath() if the document was
405          *  later manually moved to a different location.
406          */
407         support::DocFileName getReferencedFileName(std::string const & fn) const;
408
409         /// Format a file name for LaTeX output (absolute or relative or filename only,
410         /// depending on file and context)
411         std::string const prepareFileNameForLaTeX(std::string const &,
412                                         std::string const &, bool nice) const;
413
414         /** Returns a vector of bibliography (*.bib) file paths suitable for the
415          *  output in the respective BibTeX/Biblatex macro
416          */
417         std::vector<docstring> const prepareBibFilePaths(OutputParams const &,
418                                     support::FileNamePairList const bibfilelist,
419                                     bool const extension = true) const;
420
421         /** Returns the path where a local layout file lives.
422          *  An empty string is returned for standard system and user layouts.
423          *  If possible, it is always relative to the buffer path.
424          */
425         std::string layoutPos() const;
426
427         /** Set the path to a local layout file.
428          *  This must be an absolute path but, if possible, it is always
429          *  stored as relative to the buffer path.
430          */
431         void setLayoutPos(std::string const & path);
432
433         /** A transformed version of the file name, adequate for LaTeX.
434             \param no_path optional if \c true then the path is stripped.
435         */
436         std::string latexName(bool no_path = true) const;
437
438         /// Get the name and type of the log.
439         std::string logName(LogType * type = 0) const;
440
441         /// Set document's parent Buffer.
442         void setParent(Buffer const *);
443         Buffer const * parent() const;
444
445         /** Get the document's master (or \c this if this is not a
446             child document)
447          */
448         Buffer const * masterBuffer() const;
449
450         /// \return true if \p child is a child of this \c Buffer.
451         bool isChild(Buffer * child) const;
452
453         /// \return true if this \c Buffer has children
454         bool hasChildren() const;
455
456         /// \return a list of the direct children of this Buffer.
457         /// this list has no duplicates and is in the order in which
458         /// the children appear.
459         ListOfBuffers getChildren() const;
460
461         /// \return a list of all descendents of this Buffer (children,
462         /// grandchildren, etc). this list has no duplicates and is in
463         /// the order in which the children appear.
464         ListOfBuffers getDescendents() const;
465
466         /// Collect all relative buffers, in the order in which they appear.
467         /// I.e., the "root" Buffer is first, then its first child, then any
468         /// of its children, etc. However, there are no duplicates in this
469         /// list.
470         /// This is "stable", too, in the sense that it returns the same
471         /// thing from whichever Buffer it is called.
472         ListOfBuffers allRelatives() const;
473
474         /// Is buffer read-only? True if it has either the read-only flag or the
475         /// externally modified flag.
476         bool isReadonly() const;
477
478         /// Does the buffer have the read-only flag?
479         bool hasReadonlyFlag() const;
480
481         /// Set buffer read-only flag
482         void setReadonly(bool flag = true);
483
484         /** Validate a buffer for LaTeX.
485             This validates the buffer, and returns a struct for use by
486             #makeLaTeX# and others. Its main use is to figure out what
487             commands and packages need to be included in the LaTeX file.
488             It (should) also check that the needed constructs are there
489             (i.e. that the \refs points to coresponding \labels). It
490             should perhaps inset "error" insets to help the user correct
491             obvious mistakes.
492         */
493         void validate(LaTeXFeatures &) const;
494
495         /// Reference information is cached in the Buffer, so we do not
496         /// have to check or read things over and over.
497         ///
498         /// There are two caches.
499         ///
500         /// One is a cache of the BibTeX files from which reference info is
501         /// being gathered. This cache is PER BUFFER, and the cache for the
502         /// master essentially includes the cache for its children. This gets
503         /// invalidated when an InsetBibtex is created, deleted, or modified.
504         ///
505         /// The other is a cache of the reference information itself. This
506         /// exists only in the master buffer, and when it needs to be updated,
507         /// the children add their information to the master's cache.
508
509         /// Calling this method invalidates the cache and so requires a
510         /// re-read.
511         void invalidateBibinfoCache() const;
512         /// This invalidates the cache of files we need to check.
513         void invalidateBibfileCache() const;
514         /// Updates the cached bibliography information, checking first to see
515         /// whether the cache is valid. If so, we do nothing. If not, then we
516         /// reload all the BibTeX info.
517         /// Note that this operates on the master document.
518         void reloadBibInfoCache() const;
519         /// \return the bibliography information for this buffer's master,
520         /// or just for it, if it isn't a child.
521         BiblioInfo const & masterBibInfo() const;
522         /// collect bibliography info from the various insets in this buffer.
523         void collectBibKeys() const;
524         /// add some BiblioInfo to our cache
525         void addBiblioInfo(BiblioInfo const & bi) const;
526         /// add a single piece of bibliography info to our cache
527         void addBibTeXInfo(docstring const & key, BibTeXInfo const & bi) const;
528         ///
529         void makeCitationLabels() const;
530         ///
531         bool citeLabelsValid() const;
532         ///
533         void getLabelList(std::vector<docstring> &) const;
534
535         /// This removes the .aux and .bbl files from the temp dir.
536         void removeBiblioTempFiles() const;
537
538         ///
539         void changeLanguage(Language const * from, Language const * to);
540
541         ///
542         bool isMultiLingual() const;
543         ///
544         std::set<Language const *> getLanguages() const;
545
546         ///
547         BufferParams & params();
548         BufferParams const & params() const;
549         ///
550         BufferParams const & masterParams() const;
551
552         /** The list of paragraphs.
553             This is a linked list of paragraph, this list holds the
554             whole contents of the document.
555          */
556         ParagraphList & paragraphs();
557         ParagraphList const & paragraphs() const;
558
559         /// LyX version control object.
560         LyXVC & lyxvc();
561         LyXVC const & lyxvc() const;
562
563         /// Where to put temporary files.
564         std::string const temppath() const;
565
566         /// Used when typesetting to place errorboxes.
567         TexRow const & texrow() const;
568         TexRow & texrow();
569
570         ///
571         ParIterator par_iterator_begin();
572         ///
573         ParConstIterator par_iterator_begin() const;
574         ///
575         ParIterator par_iterator_end();
576         ///
577         ParConstIterator par_iterator_end() const;
578
579         // Position of the child buffer where it appears first in the master.
580         DocIterator firstChildPosition(Buffer const * child);
581
582         /** \returns true only when the file is fully loaded.
583          *  Used to prevent the premature generation of previews
584          *  and by the citation inset.
585          */
586         bool isFullyLoaded() const;
587         /// Set by buffer_funcs' newFile.
588         void setFullyLoaded(bool);
589
590         /// FIXME: Needed by RenderPreview.
591         graphics::PreviewLoader * loader() const;
592         /// Update the LaTeX preview snippets associated with this buffer
593         void updatePreviews() const;
594         /// Remove any previewed LaTeX snippets associated with this buffer
595         void removePreviews() const;
596         ///
597         graphics::Cache & graphicsCache() const;
598
599         /// Our main text (inside the top InsetText)
600         Text & text() const;
601
602         /// Our top InsetText
603         Inset & inset() const;
604
605         //
606         // Macro handling
607         //
608         /// Collect macro definitions in paragraphs
609         void updateMacros() const;
610         /// Iterate through the whole buffer and try to resolve macros
611         void updateMacroInstances(UpdateType) const;
612
613         /// List macro names of this buffer, the parent and the children
614         void listMacroNames(MacroNameSet & macros) const;
615         /// Collect macros of the parent and its children in front of this buffer.
616         void listParentMacros(MacroSet & macros, LaTeXFeatures & features) const;
617
618         /// Return macro defined before pos (or in the master buffer)
619         MacroData const * getMacro(docstring const & name, DocIterator const & pos, bool global = true) const;
620         /// Return macro defined anywhere in the buffer (or in the master buffer)
621         MacroData const * getMacro(docstring const & name, bool global = true) const;
622         /// Return macro defined before the inclusion of the child
623         MacroData const * getMacro(docstring const & name, Buffer const & child, bool global = true) const;
624
625         /// Collect user macro names at loading time
626         typedef std::set<docstring> UserMacroSet;
627         mutable UserMacroSet usermacros;
628
629         /// Replace the inset contents for insets which InsetCode is equal
630         /// to the passed \p inset_code.
631         void changeRefsIfUnique(docstring const & from, docstring const & to);
632
633         /// get source code (latex/docbook) for some paragraphs, or all paragraphs
634         /// including preamble
635         /// returns nullptr if Id to Row conversion is unsupported
636         unique_ptr<TexRow> getSourceCode(odocstream & os,
637                         std::string const & format, pit_type par_begin,
638                         pit_type par_end, OutputWhat output, bool master) const;
639
640         /// Access to error list.
641         /// This method is used only for GUI visualisation of Buffer related
642         /// errors (like parsing or LateX compilation). This method is const
643         /// because modifying the returned ErrorList does not touch the document
644         /// contents.
645         ErrorList & errorList(std::string const & type) const;
646
647         /// The Toc backend.
648         /// This is useful only for screen visualisation of the Buffer. This
649         /// method is const because modifying this backend does not touch
650         /// the document contents.
651         TocBackend & tocBackend() const;
652
653         ///
654         Undo & undo();
655
656         /// This function is called when the buffer is changed.
657         void changed(bool update_metrics) const;
658         ///
659         void setChild(DocIterator const & dit, Buffer * child);
660         ///
661         void updateTocItem(std::string const &, DocIterator const &) const;
662         /// This function is called when the buffer structure is changed.
663         void structureChanged() const;
664         /// This function is called when some parsing error shows up.
665         void errors(std::string const & err, bool from_master = false) const;
666         /// This function is called when the buffer busy status change.
667         void setBusy(bool on) const;
668         /// Update window titles of all users.
669         void updateTitles() const;
670         /// Reset autosave timers for all users.
671         void resetAutosaveTimers() const;
672         ///
673         void message(docstring const & msg) const;
674
675         ///
676         void setGuiDelegate(frontend::GuiBufferDelegate * gui);
677         ///
678         bool hasGuiDelegate() const;
679
680         ///
681         ExportStatus doExport(std::string const & target, bool put_in_tempdir) const;
682         /// Export buffer to format \p format and open the result in a suitable viewer.
683         /// Note: This has nothing to do with preview of graphics or math formulas.
684         ExportStatus preview(std::string const & format) const;
685         /// true if there was a previous preview this session of this buffer and
686         /// there was an error on the previous preview of this buffer.
687         bool lastPreviewError() const;
688
689 private:
690         ///
691         ExportStatus doExport(std::string const & target, bool put_in_tempdir,
692                 std::string & result_file) const;
693         /// target is a format name optionally followed by a space
694         /// and a destination file-name
695         ExportStatus doExport(std::string const & target, bool put_in_tempdir,
696                 bool includeall, std::string & result_file) const;
697         ///
698         ExportStatus preview(std::string const & format, bool includeall) const;
699         ///
700         void setMathFlavor(OutputParams & op) const;
701
702 public:
703         ///
704         bool isExporting() const;
705
706         ///
707         typedef std::vector<std::pair<Inset *, ParIterator> > References;
708         ///
709         References const & references(docstring const & label) const;
710         ///
711         void addReference(docstring const & label, Inset * inset, ParIterator it);
712         ///
713         void clearReferenceCache() const;
714         ///
715         void setInsetLabel(docstring const & label, InsetLabel const * il);
716         ///
717         InsetLabel const * insetLabel(docstring const & label) const;
718
719         /// return a list of all used branches (also in children)
720         void getUsedBranches(std::list<docstring> &, bool const from_master = false) const;
721
722         /// sets the buffer_ member for every inset in this buffer.
723         // FIXME This really shouldn't be needed, but at the moment it's not
724         // clear how to do it just for the individual pieces we need.
725         void setBuffersForInsets() const;
726         /// Updates screen labels and some other information associated with
727         /// insets and paragraphs. Actually, it's more like a general "recurse
728         /// through the Buffer" routine, that visits all the insets and paragraphs.
729         void updateBuffer() const { updateBuffer(UpdateMaster, InternalUpdate); }
730         /// \param scope: whether to start with the master document or just
731         /// do this one.
732         /// \param output: whether we are preparing for output.
733         void updateBuffer(UpdateScope scope, UpdateType utype) const;
734         ///
735         void updateBuffer(ParIterator & parit, UpdateType utype) const;
736
737         /// Spellcheck starting from \p from.
738         /// \p from initial position, will then points to the next misspelled
739         ///    word.
740         /// \p to will points to the end of the next misspelled word.
741         /// \p word_lang will contain the found misspelled word.
742         /// \return progress if a new word was found.
743         int spellCheck(DocIterator & from, DocIterator & to,
744                 WordLangTuple & word_lang, docstring_list & suggestions) const;
745         ///
746         void checkChildBuffers();
747         ///
748         void checkMasterBuffer();
749
750         /// If the document is being saved to a new location and the named file
751         /// exists at the old location, return its updated path relative to the
752         /// new buffer path if possible, otherwise return its absolute path.
753         /// In all other cases, this is a no-op and name is returned unchanged.
754         /// If a non-empty ext is given, the existence of name.ext is checked
755         /// but the returned path will not contain this extension.
756         /// Similarly, when loading a document that was moved from the location
757         /// where it was saved, return the correct path relative to the new
758         /// location.
759         std::string includedFilePath(std::string const & name,
760                                 std::string const & ext = empty_string()) const;
761
762         /// compute statistics between \p from and \p to
763         /// \p from initial position
764         /// \p to points to the end position
765         /// \p skipNoOutput if notes etc. should be ignored
766         void updateStatistics(DocIterator & from, DocIterator & to,
767                                                   bool skipNoOutput = true) const;
768         /// statistics accessor functions
769         int wordCount() const;
770         int charCount(bool with_blanks) const;
771
772         // this is const because it does not modify the buffer's real contents,
773         // only the mutable flag.
774         void setChangesPresent(bool) const;
775         bool areChangesPresent() const;
776         void updateChangesPresent() const;
777
778 private:
779         friend class MarkAsExporting;
780         /// mark the buffer as busy exporting something, or not
781         void setExportStatus(bool e) const;
782
783         ///
784         References & getReferenceCache(docstring const & label);
785         /// Change name of buffer. Updates "read-only" flag.
786         void setFileName(support::FileName const & fname);
787         ///
788         void getLanguages(std::set<Language const *> &) const;
789         /// Checks whether any of the referenced bibfiles have changed since the
790         /// last time we loaded the cache. Note that this does NOT update the
791         /// cached information.
792         void checkIfBibInfoCacheIsValid() const;
793         /// Update the list of all bibfiles in use (including bibfiles
794         /// of loaded child documents).
795         void updateBibfilesCache(UpdateScope scope = UpdateMaster) const;
796         /// Return the list with all bibfiles in use (including bibfiles
797         /// of loaded child documents).
798         support::FileNamePairList const &
799                 getBibfilesCache(UpdateScope scope = UpdateMaster) const;
800         ///
801         void collectChildren(ListOfBuffers & children, bool grand_children) const;
802
803         /// noncopyable
804         Buffer(Buffer const &);
805         void operator=(Buffer const &);
806
807         /// Use the Pimpl idiom to hide the internals.
808         class Impl;
809         /// The pointer never changes although *pimpl_'s contents may.
810         Impl * const d;
811 };
812
813
814 /// Helper class, to guarantee that the export status
815 /// gets reset properly. To use, simply create a local variable:
816 ///    MarkAsExporting mex(bufptr);
817 /// and leave the rest to us.
818 class MarkAsExporting {
819 public:
820         MarkAsExporting(Buffer const * buf) : buf_(buf)
821         {
822                 buf_->setExportStatus(true);
823         }
824         ~MarkAsExporting()
825         {
826                 buf_->setExportStatus(false);
827         }
828 private:
829         Buffer const * const buf_;
830 };
831
832
833 } // namespace lyx
834
835 #endif