Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port other-buffer #1476

Open
brotzeit opened this issue May 4, 2019 · 1 comment · May be fixed by #1489
Open

Port other-buffer #1476

brotzeit opened this issue May 4, 2019 · 1 comment · May be fixed by #1489
Labels
Active PR There is a PR that resolves this issue. middle level task

Comments

@brotzeit
Copy link
Member

brotzeit commented May 4, 2019

DEFUN ("other-buffer", Fother_buffer, Sother_buffer, 0, 3, 0,
       doc: /* Return most recently selected buffer other than BUFFER.
Buffers not visible in windows are preferred to visible buffers, unless
optional second argument VISIBLE-OK is non-nil.  Ignore the argument
BUFFER unless it denotes a live buffer.  If the optional third argument
FRAME specifies a live frame, then use that frame's buffer list instead
of the selected frame's buffer list.

The buffer is found by scanning the selected or specified frame's buffer
list first, followed by the list of all buffers.  If no other buffer
exists, return the buffer `*scratch*' (creating it if necessary).  */)
  (Lisp_Object buffer, Lisp_Object visible_ok, Lisp_Object frame)
{
  struct frame *f = decode_live_frame (frame);
  Lisp_Object tail = f->buffer_list, pred = f->buffer_predicate;
  Lisp_Object buf, notsogood = Qnil;

  /* Consider buffers that have been seen in the frame first.  */
  for (; CONSP (tail); tail = XCDR (tail))
    {
      buf = XCAR (tail);
      if (candidate_buffer (buf, buffer)
	  /* If the frame has a buffer_predicate, disregard buffers that
	     don't fit the predicate.  */
	  && (NILP (pred) || !NILP (call1 (pred, buf))))
	{
	  if (!NILP (visible_ok)
	      || NILP (Fget_buffer_window (buf, Qvisible)))
	    return buf;
	  else if (NILP (notsogood))
	    notsogood = buf;
	}
    }

  /* Consider alist of all buffers next.  */
  FOR_EACH_LIVE_BUFFER (tail, buf)
    {
      if (candidate_buffer (buf, buffer)
	  /* If the frame has a buffer_predicate, disregard buffers that
	     don't fit the predicate.  */
	  && (NILP (pred) || !NILP (call1 (pred, buf))))
	{
	  if (!NILP (visible_ok)
	      || NILP (Fget_buffer_window (buf, Qvisible)))
	    return buf;
	  else if (NILP (notsogood))
	    notsogood = buf;
	}
    }

  if (!NILP (notsogood))
    return notsogood;
  else
    {
      AUTO_STRING (scratch, "*scratch*");
      buf = Fget_buffer (scratch);
      if (NILP (buf))
	{
	  buf = Fget_buffer_create (scratch);
	  Fset_buffer_major_mode (buf);
	}
      return buf;
    }
}
@simon-frankau
Copy link
Contributor

I'd like to take this one as a follow-up to #1448.

@simon-frankau simon-frankau linked a pull request May 10, 2019 that will close this issue
@agraven agraven added this to To do in Porting efforts via automation May 16, 2019
@agraven agraven added the Active PR There is a PR that resolves this issue. label May 16, 2019
@agraven agraven moved this from To do to In progress in Porting efforts May 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Active PR There is a PR that resolves this issue. middle level task
Projects
Porting efforts
  
In progress
Development

Successfully merging a pull request may close this issue.

3 participants