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