コード例 #1
0
    def _make_buffer(self, name, contents, empty_goto=True, switch=False,
                     window='other', modes=[], fit_lines=None):
        """Make an emacs buffer

        `window` can be one of `None`, 'current' or 'other'.
        """
        new_buffer = lisp.get_buffer_create(name)
        lisp.set_buffer(new_buffer)
        lisp.toggle_read_only(-1)
        lisp.erase_buffer()
        if contents or empty_goto:
            lisp.insert(contents)
            for mode in modes:
                lisp[mode + '-mode']()
            lisp.buffer_disable_undo(new_buffer)
            lisp.toggle_read_only(1)
            if switch:
                if window == 'current':
                    lisp.switch_to_buffer(new_buffer)
                else:
                    lisp.switch_to_buffer_other_window(new_buffer)
                lisp.goto_char(lisp.point_min())
            elif window == 'other':
                new_window = lisp.display_buffer(new_buffer)
                lisp.set_window_point(new_window, lisp.point_min())
                if fit_lines and lisp.fboundp(lisp['fit-window-to-buffer']):
                    lisp.fit_window_to_buffer(new_window, fit_lines)
                    lisp.bury_buffer(new_buffer)
        return new_buffer
コード例 #2
0
    def _make_buffer(self,
                     name,
                     contents,
                     empty_goto=True,
                     switch=False,
                     window='other',
                     modes=[],
                     fit_lines=None):
        """Make an emacs buffer

        `window` can be one of `None`, 'current' or 'other'.
        """
        new_buffer = lisp.get_buffer_create(name)
        lisp.set_buffer(new_buffer)
        lisp.toggle_read_only(-1)
        lisp.erase_buffer()
        if contents or empty_goto:
            lisp.insert(contents)
            for mode in modes:
                lisp[mode + '-mode']()
            lisp.buffer_disable_undo(new_buffer)
            lisp.toggle_read_only(1)
            if switch:
                if window == 'current':
                    lisp.switch_to_buffer(new_buffer)
                else:
                    lisp.switch_to_buffer_other_window(new_buffer)
                lisp.goto_char(lisp.point_min())
            elif window == 'other':
                new_window = lisp.display_buffer(new_buffer)
                lisp.set_window_point(new_window, lisp.point_min())
                if fit_lines and lisp.fboundp(lisp['fit-window-to-buffer']):
                    lisp.fit_window_to_buffer(new_window, fit_lines)
                    lisp.bury_buffer(new_buffer)
        return new_buffer
コード例 #3
0
def occurrences_next(arg, reset):
    lisp.switch_to_buffer_other_window('*rope-occurrences*', True)
    if reset:
        lisp.goto_char(lisp.point_min())
    lisp.forward_line(arg)
    if lisp.eobp():
        lisp.message("Cycling rope occurences")
        lisp.goto_char(lisp.point_min())
    occurrences_goto()
コード例 #4
0
def occurrences_next(arg, reset):
    lisp.switch_to_buffer_other_window('*rope-occurrences*', True)
    if reset:
        lisp.goto_char(lisp.point_min())
    lisp.forward_line(arg)
    if lisp.eobp():
        lisp.message("Cycling rope occurences")
        lisp.goto_char(lisp.point_min())
    occurrences_goto()
コード例 #5
0
 def get_text(self):
     end = lisp.buffer_size() + 1
     old_min = lisp.point_min()
     old_max = lisp.point_max()
     narrowed = (old_min != 1 or old_max != end)
     if narrowed:
         lisp.narrow_to_region(1, lisp.buffer_size() + 1)
     try:
         return lisp.buffer_string()
     finally:
         if narrowed:
             lisp.narrow_to_region(old_min, old_max)
コード例 #6
0
 def get_text(self):
     end = lisp.buffer_size() + 1
     old_min = lisp.point_min()
     old_max = lisp.point_max()
     narrowed = (old_min != 1 or old_max != end)
     if narrowed:
         lisp.narrow_to_region(1, lisp.buffer_size() + 1)
     try:
         return lisp.buffer_string()
     finally:
         if narrowed:
             lisp.narrow_to_region(old_min, old_max)
コード例 #7
0
ファイル: interface.py プロジェクト: FredSanders/emacs.d
 def _get_text(self):
     if not lisp.buffer_modified_p():
         return self._get_resource().read()
     end = lisp.buffer_size() + 1
     old_min = lisp.point_min()
     old_max = lisp.point_max()
     narrowed = (old_min != 1 or old_max != end)
     if narrowed:
         lisp.narrow_to_region(1, lisp.buffer_size() + 1)
     try:
         return lisp.buffer_string()
     finally:
         if narrowed:
             lisp.narrow_to_region(old_min, old_max)
コード例 #8
0
ファイル: bibtex.py プロジェクト: marcora/emacs
def pmfetch(pmid):
	""" Fetch and insert a BibTeX reference for PubMed article w/ given PMID at beginning of buffer. """
	try:
		# Init vars
		key = ''
		author = ''
		title = ''
		journal = ''
		year = ''
		volume = ''
		number = ''
		pages = ''
		month = ''
		note = ''
		abstract = ''
		url = ''

		# Format author
		def format_author(author):
			suffix = ''
			if author[-2:] in ('Jr', 'Sr'):
				suffix = author[-2:] + '.'
				author = author[:-3]
			elif author[-3:] in ('2nd', '3rd'):
				suffix = author[-3:]
				author = author[:-4]
			author = split(author, maxsplit=-1)
			last_name = author[0]
			initials = author[1]
			initials = list(initials)
			if suffix:
				initials.append(suffix)
			else:
				initials.append('')
			return strip(last_name + ', ' + '. '.join(initials))

		# Format and check pmid, and fetch article from PubMed
		pmid = str(pmid).strip()
		if not pmid.isdigit(): raise ValueError
		pm = PubMed.Dictionary(parser=Medline.RecordParser())
		article = pm[pmid] # Fetch article from PubMed
		if not article or not article.pubmed_id == pmid: raise ValueError
		if not article.title: raise ValueError
		else: title = article.title
		if not article.no_author and article.authors:
			authors = [format_author(author) for author in article.authors]
			author = ' and '.join(authors)
		if not article.publication_date: raise ValueError
		else: year = article.publication_date[:4]
		if not article.title_abbreviation: raise ValueError
		else: journal = article.title_abbreviation
		if not article.volume_issue: raise ValueError
		else: volume = article.volume_issue
		if not article.pagination: raise ValueError
		else: pages = article.pagination.replace('-','--')
		if article.abstract: abstract = article.abstract
		if article.issue_part_supplement: number = article.issue_part_supplement

		# Create BibTeX ref
		bib = """
@ARTICLE{%s,
   pmid = {%s},
   author = {%s},
   title = {{%s}},
   journal = {%s},
   year = {%s},
   volume = {%s},
   number = {%s},
   pages = {%s},
   month = {%s},
   abstract = {%s},
   note = {%s},
   url = {%s},
}
""" % (key,pmid,author,title,journal,year,volume,number,pages,month,abstract,note,url)

		# Insert BibTeX ref
		lisp.goto_char(lisp.point_min())
		if lisp.re_search_forward(pmid,None,True,1):
			lisp.message('Article with PMID = %s is already in buffer.' % pmid)
			return
		lisp.insert(bib)
		lisp.bibtex_clean_entry()
		lisp.bibtex_fill_entry()
		return
	except:
		lisp.message('Unable to fetch article from PubMed.  Check PMID and try again.')
		return